Skip to main content

No project description provided

Project description

acldpy

PyPI Python License: MIT Tests

Summary

This Python 3 package assigns letters to indicate statistically significant differences between treatments following pairwise comparisons. It strives to be compatible with all major Python statistics libraries.

acldpy = agnostic compact letter display for Python

Users conduct their statistical test with the library of their choice. Then, they pass their result to acldpy. The package implements algorithms that were described by Piepho and coworkers [1,2].

Installation

Install from PyPI test server:

pip install acldpy

Basic usage

To calculate the cld, you need three arguments.

  1. List of all first treatment names used in the pairwise comparisons.
  2. List of all second treatment names used in the pairwise comparisons.
  3. List of the p-values associated with each comparison.

Generally, one's input should follow this structure: i-th entry of p_values corresponds to the p-value for the comparison between the i-th entry in first_treatments and the i-th entry in second_treatments:

first_treatments = ["element 1", "element 1", "element 2"]
second_treatments = ["element 2", "element 3", "element 3"]
p_values = [0.9, 0.2, 0.01]

These three lists are passed to the run_cld function of the acldpy library. run_cld returns a dictionary where each key is a unique treatment and the value is its associated letters.

from acldpy import run_cld

cld = run_cld(first_treatments, second_treatments, p_values)
print (cld) # {'element 1': 'ab', 'element 2': 'b', 'element 3': 'a'}

Typically, these three required lists can be parsed from the returned object of a statistical test, as illustrated here with the Pingouin implementation of the Tukey-Kramer test.

import pingouin as pg
from acldpy import run_cld

penguins = pg.read_dataset("penguins") # Example dataset
tk_result = penguins.pairwise_tukey(dv='body_mass_g', between='species')
first_treatments, second_treatments, p_values = list(tk_result["A"]), list(tk_result["B"]), list(tk_result["p-tukey"])

cld = run_cld(first_treatments, second_treatments, p_values)
print (cld) # {'Adelie': 'b', 'Chinstrap': 'b', 'Gentoo': 'a'}

Besides these three lists, run_cld accepts two optional arguments:

  1. alpha (float, default: 0.05): Significance level. Two treatments are considered significantly different if their p‑value is less ("<", not "=<"!) than alpha.
  2. letter_order (None | list, default: None): If set, a list containing all treatments in the order of which they should be assigned letters to. Often, one would like to assign the letters in ascending order of the treatment mean values.
from acldpy import run_cld

first_treatments = ["element 1", "element 1", "element 1", "element 2", "element 2", "element 3"]
second_treatments = ["element 2", "element 3", "element 4", "element 3", "element 4", "element 4"]
p_values = [0.08, 0.02, 0.01, 0.2, 0.04, 0.08]
mean_values = {"element 1": 1.2, "element 2": 2.8, "element 3": 3.2, "element 4": 4.0}

cld = run_cld(first_treatments, second_treatments, p_values) # default values for alpha and letter_order
print(cld) # {'element 1': 'c', 'element 2': 'bc', 'element 3': 'ab', 'element 4': 'a'}

mean_values_sorted = dict(sorted(mean_values.items(), key=lambda item: item[1]))
cld = run_cld(first_treatments, second_treatments, p_values, alpha=0.1, letter_order=mean_values_sorted.keys())
print(cld) # {'element 1': 'a', 'element 2': 'b', 'element 3': 'b', 'element 4': 'c'}

Extra Functionality

find_cld_columns is a helper function that accepts the result objects of the most common statistical tests and returns the three required lists.

from acldpy import find_cld_columns

first_treatments, second_treatments, p_values = find_cld_columns(penguins_tk_result, "pg_tk")

Currently it works with the output of the following tests:

  1. result_type="pg_tk": pingouin's Tukey-Kramer test
  2. result_type="stm_tk": statsmodels' Tukey-Kramer test

Development and Distribution

This package is provided under the MIT license. I (NJung) am its sole developer. I encourage you to report issues, when you find them under https://github.com/anyusernameisokay/acldpy/issues. If you do so, please provide your input data, and the error you receive.

Currently, the package is still under development, and I expect that some inputs lead to unhandled exceptions. However, the package will never silently return a wrong cld!

Furthermore, the following improvements are planned:

  • Different and custom alternatives to the classical small letters.
  • Optimal utilization of NumPy under the hood.

References

[1] J. Gramm, J. Guo, F. Hüffner, R. Niedermeier, H.-P. Piepho, and R. Schmid, “Algorithms for compact letter displays: Comparison and evaluation,” Computational Statistics & Data Analysis, vol. 52, no. 2, pp. 725–736, Oct. 2006, doi: 10.1016/j.csda.2006.09.035.

[2] H.-P. Piepho, “An algorithm for a Letter-Based representation of All-Pairwise comparisons,” Journal of Computational and Graphical Statistics, vol. 13, no. 2, pp. 456–466, Jun. 2004, doi: 10.1198/1061860043515.

I am not affiliated with the authors of these studies.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acldpy-0.2.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acldpy-0.2.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file acldpy-0.2.0.tar.gz.

File metadata

  • Download URL: acldpy-0.2.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for acldpy-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f259cbe6b3b42573d4e6f6f9995b5b7345cba3595e77701114880bb6aac55bcc
MD5 074a27b6e779ea521d1e8202a3d4ab0e
BLAKE2b-256 15a43029c12e72066e153e52c4a6c45cf0b76574ef3e0390d238d0f25939d46c

See more details on using hashes here.

Provenance

The following attestation bundles were made for acldpy-0.2.0.tar.gz:

Publisher: publish-to-pypi.yml on anyusernameisokay/acldpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file acldpy-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: acldpy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for acldpy-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 41433819b09167356e236de475485f4a060713f380ccfbf216c335e1418fc7c1
MD5 20f50ad502153fbd0a148b250aee96a8
BLAKE2b-256 51b0bf2fd7dd464782720aa99609e0025d17d6b79172539bb812cb697ef2c6ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for acldpy-0.2.0-py3-none-any.whl:

Publisher: publish-to-pypi.yml on anyusernameisokay/acldpy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page