1

Using the code from https://www.r-graph-gallery.com/84-tukey-test.html , I have been trying to add letters to my boxplot, but the aov function will not work for my model because it is under lmer instead of lm.

When I use the anova function instead of the aov, the rest of the code will not work. Is there any substitution I can make there that would work?

Alicia A
  • 19
  • 2
  • 1
    Welcome! Can you make your problem reproducible, see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?rq=1 – broti Apr 20 '20 at 15:12

1 Answers1

0

The cld (compact letter display) from package multcomp can do this for different kinds of models.

library("lme4")
library("multcomp")


data <- structure(list(Group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L), .Label = c("G1", "G2", "G3"), class = "factor"), 
    Subject = structure(c(1L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 8L, 9L, 10L, 11L, 12L, 13L, 
    14L, 15L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 8L, 9L, 10L, 11L, 12L, 
    13L, 14L, 15L, 2L, 3L, 4L, 5L, 6L, 7L), .Label = c("S1", 
    "S10", "S11", "S12", "S13", "S14", "S15", "S2", "S3", "S4", 
    "S5", "S6", "S7", "S8", "S9"), class = "factor"), Value = c(9.83, 
    13.62, 13.2, 14.69, 9.27, 11.68, 14.65, 12.21, 11.58, 13.58, 
    12.49, 10.28, 12.22, 12.58, 15.43, 9.47, 11.47, 10.79, 10.66, 
    10.87, 12.98, 12.85, 8.67, 10.45, 13.62, 13.64, 12.46, 8.66, 
    10.66, 13.18, 11.97, 13.56, 11.83, 14.02, 11.38, 14.15, 13.22, 
    9.14, 11.66, 14.2, 14.18, 11.26, 11.98, 13.77, 11.57)), 
    row.names = c(NA, -45L), class = "data.frame")


model <- lmer (Value~Group + (1|Subject), data = data)
tuk <- glht(model, linfct = mcp(Group = "Tukey"))
tuk.cld <- cld(tuk)
plot(tuk.cld)

The example was adapted from: https://stats.stackexchange.com/questions/237512/how-to-perform-post-hoc-test-on-lmer-model

For additional things regarding mixed models, please consider https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html

tpetzoldt
  • 5,338
  • 2
  • 12
  • 29