scikit_posthocs.compact_letter_display
- scikit_posthocs.compact_letter_display(p_values: DataFrame | ndarray, alpha: float = 0.05, names: List | None = None, maxiter: int = 100) Series
Compact Letter Display (CLD) for pairwise comparison results.
Assigns letters to groups based on pairwise significance. Groups sharing at least one letter are not significantly different from each other. This provides a compact summary of pairwise comparison results that is commonly used in publications (e.g. as annotations on bar plots).
- Parameters:
p_values (Union[DataFrame, np.ndarray]) – Symmetric matrix of p-values from any
posthoc_*function. Diagonal values are ignored (treated as non-significant).alpha (float = 0.05) – Significance level. Pairs with p-values >= alpha are considered not significantly different.
names (Optional[List] = None) – Group names used as the index of the returned Series. If
Noneandp_valuesis a DataFrame, its index is used; otherwise integer indices0, 1, ..., k-1are used.maxiter (int = 100) – Maximum number of iterations for the set-intersection step.
- Returns:
result – Series mapping each group name to a letter string. Groups sharing a letter are not significantly different. Spaces indicate that a group does not belong to that letter group.
- Return type:
pandas.Series
- Raises:
ValueError – If the number of letter groups exceeds the available alphabet length (52: a-z then A-Z).
- Warns:
RuntimeWarning – If the algorithm does not converge within
maxiteriterations.
Notes
Uses the set-intersection algorithm described by Perktold (unpublished) which is equivalent to the sweep-and-absorb algorithm of Piepho (2004) for standard use cases. Groups are sorted by their smallest member index to ensure a deterministic letter assignment.
References
Piepho, Hans-Peter (2004). An Algorithm for a Letter-Based Representation of All-Pairwise Comparisons. Journal of Computational and Graphical Statistics, 13(2), 456-466. https://doi.org/10.1198/1061860043515
Examples
>>> import scikit_posthocs as sp >>> x = [[1, 2, 1, 3, 1, 4], [12, 3, 11, 9, 3, 8, 1], ... [10, 22, 12, 9, 8, 3], [14, 12, 16, 17, 5, 9]] >>> pc = sp.posthoc_dunn(x, p_adjust='holm') >>> sp.compact_letter_display(pc, alpha=0.05) 1 a 2 ab 3 b 4 b Name: letters, dtype: str