0
votes

I'm having trouble generating a compact letter display for my results. I've run an ANOVA followed by Tukey's HSD to generate the p values for each pair, but I do not know how (or if it is possible?) to assign letters to these p values to show which pairs are significant from each other.

csa.anova<-aov(rate~temp*light,data=csa.per.chl) summary(csa.anova) TukeyHSD(csa.anova)

This runs the tests I need, but I don't know how to assign letters to each p value to show which pairs are significant.

3
Your example is not reproducible, please edit the question with the output of dput(head(csa.per.chl, 20)). What are the letters you want to assign to what ranges of p-values? Say, A: 0.00-0.05, etc? What, exactly? Edit the question with that information, please.Rui Barradas
What do you mean by "assign letters"? For others looking at this, here is an example using mtcars: m <- mtcars m$cyl <- as.factor(m$cyl); m$gear <- as.factor(m$gear) m.anova<-aov(mpg~cyl*gear,data=m) summary(m.anova) TukeyHSD(m.anova)Monk
A CLD is a misleading graphic because it shows what comparisons were NOT found significant. So my answer is "just don't" and instead show a matrix of P values, or confidence intervals for differences of measure, or some other graphic that is not misleading.Russ Lenth

3 Answers

1
votes

You need to install the multcomp package first. It can compute the Tukey HSD Test and returns an object that has summary and plot methods. The package also has a function (cld) to print the "compact letter display." As an example we can use the iris data set that comes with R:

library(multcomp)
data(iris)
iris.aov <- aov(Petal.Length~Species, iris)
iris.tukey <- glht(iris.aov, linfct=mcp(Species="Tukey"))
cld(iris.tukey)
#     setosa versicolor  virginica 
#        "a"        "b"        "c" 
0
votes

Find more details here.

mod <- lm(Sepal.Width ~ Species, data = iris)

mod_means_contr <- emmeans::emmeans(object = mod,
                                    pairwise ~ "Species",
                                    adjust = "tukey")

mod_means <- multcomp::cld(object = mod_means_contr$emmeans,
                           Letters = letters)

library(ggplot2)

ggplot(data = mod_means,
       aes(x = Species, y = emmean)) +
  geom_errorbar(aes(ymin = lower.CL, 
                    ymax = upper.CL), 
                width = 0.2) +
  geom_point() +
  geom_text(aes(label = gsub(" ", "", .group)),
            position = position_nudge(x = 0.2)) +
  labs(caption = "Means followed by a common letter are\nnot significantly different according to the Tukey-test")

Created on 2021-06-03 by the reprex package (v2.0.0)

-1
votes

I cannot make this code work:

data("iris")
iris.aov<-aov(Petal.Length~Species,iris)
iris.tukey<-glht(iris.aov,linfct=mcp(Species="Tukey"))

Here is the error triggered:

Error in glht(iris.aov, linfct = mcp(Species = "Tukey")) : could not find function "glht"