1

使用来自https://www.r-graph-gallery.com/84-tukey-test.html的代码,我一直在尝试向我的箱线图添加字母,但是 aov 函数不适用于我的模型,因为它是在 lmer 而不是 lm 下。

当我使用 anova 函数而不是 aov 时,其余代码将不起作用。我可以在那里做任何替代品吗?

4

1 回答 1

0

multcomp包中的cld(compact letter display)可以针对不同类型的模型执行此操作。

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)

该示例改编自:https ://stats.stackexchange.com/questions/237512/how-to-perform-post-hoc-test-on-lmer-model

有关混合模型的其他信息,请考虑https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html

于 2020-04-20T16:15:42.243 回答