Introduction
The cld package provides an easy and consistent way to create compact letter displays (CLDs) for visualizing results of pairwise statistical comparisons. Groups sharing the same letter are not significantly different from each other β a convention widely used in agricultural, biological, and statistical publications.
Why Use cld?
π Universal compatibility - Works with outputs from
base R, PMCMRplus, rstatix, DescTools, and custom data frames
π― One function - make_cld() handles all
input types automatically
π Publication-ready - Generate clean, professional
statistical grouping labels
π Informative - Stores metadata (alpha, method,
comparison counts) for transparency
π οΈ Well-tested - 500+ tests ensuring reliability across
all methods
Interpretation Rules
β At least one shared letter β Groups are
NOT significantly different
β
No shared letters β Groups ARE
significantly different
Examples:
- β Groups with βcβ and βcβ share letter βcβ β difference is not significant
- β Groups with βaβ and βabβ share letter βaβ β difference is not significant
- β Groups βabβ and βbcβ share letter βbβ β difference is not significant
- β Groups βabcβ and βbcdβ share letters βbβ, and βcβ β difference is not significant
- β Groups with βaβ and βcβ share no letters β significant difference
- β Groups with βabdβ and βceβ share no letters β significant difference
Quick Start
The cld package works with various statistical test outputs. Hereβs a simple example:
# Run a pairwise test
test_result <- pairwise.wilcox.test(chickwts$weight, chickwts$feed, exact = FALSE)
# Generate compact letter display
make_cld(test_result)
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.05
#> Method: Wilcoxon rank sum test with continuity correction
#>
#> group cld spaced_cld
#> casein a a__
#> horsebean b _b_
#> linseed bc _bc
#> meatmeal ac a_c
#> soybean c __c
#> sunflower a a__Interpretation:
- Groups sharing at least one letter are not significantly different (e.g., casein and sunflower both have βaβ);
- Groups with no shared letters are significantly different (e.g., horsebean βbβ and soybean βcβ).
Basic Usage with Base R Tests
Pairwise Wilcoxon Test
# Pairwise Wilcoxon rank sum test
result <- pairwise.wilcox.test(chickwts$weight, chickwts$feed, exact = FALSE)
make_cld(result)
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.05
#> Method: Wilcoxon rank sum test with continuity correction
#>
#> group cld spaced_cld
#> casein a a__
#> horsebean b _b_
#> linseed bc _bc
#> meatmeal ac a_c
#> soybean c __c
#> sunflower a a__Pairwise t-test
# Pairwise t-test
result2 <- pairwise.t.test(chickwts$weight, chickwts$feed)
make_cld(result2)
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.05
#> Method: t tests with pooled SD
#>
#> group cld spaced_cld
#> casein a a__
#> horsebean b _b_
#> linseed bc _bc
#> meatmeal ac a_c
#> soybean c __c
#> sunflower a a__Understanding the Output
Structure
The make_cld() function returns a
cld_object (enhanced data frame) with:
Columns:
- group - Names of the groups being compared
- cld - Compact letter display (letters only)
- spaced_cld - Monospaced version for alignment (underscores replace spaces)
Attributes (metadata):
- alpha - Significance level used
- method - Statistical test/method name
- n_comparisons - Total number of pairwise comparisons
- n_significant - Number of significant differences found
result <- pairwise.wilcox.test(chickwts$weight, chickwts$feed, exact = FALSE)
cld_result <- make_cld(result)
# View result
cld_result
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.05
#> Method: Wilcoxon rank sum test with continuity correction
#>
#> group cld spaced_cld
#> casein a a__
#> horsebean b _b_
#> linseed bc _bc
#> meatmeal ac a_c
#> soybean c __c
#> sunflower a a__
# Access metadata
attributes(cld_result)[c("alpha", "method", "n_comparisons", "n_significant")]
#> $alpha
#> [1] 0.05
#>
#> $method
#> [1] "Wilcoxon rank sum test with continuity correction"
#>
#> $n_comparisons
#> [1] 15
#>
#> $n_significant
#> [1] 8Working with the Output
Convert to Other Formats
# Extract as named character vector
letters_only <- as.character(cld_result)
letters_only
#> casein horsebean linseed meatmeal soybean sunflower
#> "a" "b" "bc" "ac" "c" "a"
# Convert back to plain data frame (removes metadata)
plain_df <- as.data.frame(cld_result)
class(plain_df)
#> [1] "data.frame"Adjust Significance Level
result <- pairwise.wilcox.test(chickwts$weight, chickwts$feed, exact = FALSE)
# Standard (alpha = 0.05)
make_cld(result, alpha = 0.05)
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.05
#> Method: Wilcoxon rank sum test with continuity correction
#>
#> group cld spaced_cld
#> casein a a__
#> horsebean b _b_
#> linseed bc _bc
#> meatmeal ac a_c
#> soybean c __c
#> sunflower a a__
# More stringent (alpha = 0.01)
make_cld(result, alpha = 0.01)
#> Compact Letter Display (CLD)
#> Signif. level (alpha): 0.01
#> Method: Wilcoxon rank sum test with continuity correction
#>
#> group cld spaced_cld
#> casein ab ab_
#> horsebean c __c
#> linseed ac a_c
#> meatmeal ab ab_
#> soybean ab ab_
#> sunflower b _b_