如何对lmer模型执行事后测试?


18

这是我的数据框:

Group   <- c("G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G1","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G2","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3","G3")
Subject <- c("S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","S14","S15","S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","S14","S15","S1","S2","S3","S4","S5","S6","S7","S8","S9","S10","S11","S12","S13","S14","S15")
Value   <- c(9.832217741,13.62390117,13.19671612,14.68552076,9.26683366,11.67886655,14.65083473,12.20969772,11.58494621,13.58474896,12.49053635,10.28208078,12.21945867,12.58276212,15.42648969,9.466436017,11.46582655,10.78725485,10.66159358,10.86701127,12.97863424,12.85276916,8.672953949,10.44587257,13.62135205,13.64038394,12.45778874,8.655142642,10.65925259,13.18336949,11.96595556,13.5552118,11.8337142,14.01763101,11.37502161,14.14801305,13.21640866,9.141392359,11.65848845,14.20350364,14.1829714,11.26202565,11.98431285,13.77216009,11.57303893)

data <- data.frame(Group, Subject, Value)

然后,我运行一个线性混合效果模型来比较“价值”上这3组的差异,其中“主题”是随机因素:

library(lme4)
library(lmerTest)
model <- lmer (Value~Group + (1|Subject), data = data)
summary(model)

结果是:

Fixed effects:
            Estimate Std. Error       df t value Pr(>|t|)    
(Intercept) 12.48771    0.42892 31.54000  29.114   <2e-16 ***
GroupG2     -1.12666    0.46702 28.00000  -2.412   0.0226 *  
GroupG3      0.03828    0.46702 28.00000   0.082   0.9353    

但是,如何比较Group2和Group3?学术文章中的惯例是什么?

Answers:


16

您可以使用emmeans::emmeans()lmerTest::difflsmeans()multcomp::glht()

我更喜欢emmeans(以前lsmeans)。

library(emmeans)
emmeans(model, list(pairwise ~ Group), adjust = "tukey")

Note difflsmeans无法校正多个比较,而是使用Satterthwaite方法作为默认值来计算自由度,而不是使用emmeans的Kenward-Roger方法。

library(lmerTest)
difflsmeans(model, test.effs = "Group")

multcomp::glht()方法在Hack-R对此问题的另一个答案中进行了描述。

另外,您可以通过加载lmerTest,然后使用来获取ANOVA p值anova

library(lmerTest)
anova(model)

明确一点,您打算针对每个主题对价值进行三次评估,对吗?看起来“组”是对象内部的,而不是对象之间的。


1
我只想补充一下Kayle Sawyer的答复,即不赞成使用lsmeans软件包,而推荐使用emmeans软件包
Downhiller

请注意,如果指定了库,则必须使用lmerTest :: lmer()而非ame()的lme4 :: lmer()来显示p值。
凯尔·索耶

11

拟合lmer模型后,您可以对模型对象执行ANOVA,MANOVA和多个比较过程,如下所示:

library(multcomp)
summary(glht(model, linfct = mcp(Group = "Tukey")), test = adjusted("holm"))
   Simultaneous Tests for General Linear Hypotheses

Multiple Comparisons of Means: Tukey Contrasts


Fit: lmer(formula = Value ~ Group + (1 | Subject), data = data)

Linear Hypotheses:
             Estimate Std. Error z value Pr(>|z|)  
G2 - G1 == 0 -1.12666    0.46702  -2.412   0.0378 *
G3 - G1 == 0  0.03828    0.46702   0.082   0.9347  
G3 - G2 == 0  1.16495    0.46702   2.494   0.0378 *
---
Signif. codes:  0***0.001**0.01*0.05 ‘.’ 0.1 ‘ ’ 1
(Adjusted p values reported -- holm method)

至于学术论文中的惯例,这将因领域,期刊和特定主题而有很大不同。因此,对于这种情况,只需阅读相关文章并查看其作用即可。


谢谢。但是实际上使用了哪种调整?是土耳其还是毛呢?为什么两者都出现在事后测试中?
平坪

@PingTang不客气。这是对所有对多重比较的Bonferroni-Holm校正。当然,那只是一个选择。您也可以这样做summary(glht(model, linfct = mcp(Group = "Tukey")))。如果您想查看可以执行的各种测试的完整学术/统计描述,请查阅参考资料,?glht以及multicomp更一般的参考资料。我认为,徐(Hsu)1996将是主要作品。
Hack-R

3
@PingTang mcp函数,Group = Tukey正义的意思是比较变量“ Group”中的所有成对组。这并不意味着调整Tukey。
Sal Mangiafico
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.