lmerTest我有一个数据集(和相应的混合模型),当使用 I 型(顺序,注意它是最后一个)和 II 型(使用和car包)进行测试时,它在双向交互之一中获得了非常不同的 p 值。
顺序和car包“同意”并且lmerTest包是不同的。
这些方法在做什么,为什么它们不同,哪些是“正确的”?
(请注意,这里有很多关于 Type I/II/III 的问题,但我没有看到回答这个关于 Type II 的特定问题。另外,当我使用 R 并且对 R 中使用的特定实现感兴趣时,更大的问题是统计问题,而不是编码问题。)
library(lme4)
library(lmerTest)
library(car)
d <- data.frame(
Y = c(6, 4, 5, 7, 6, 8, 9, 0, 10, 9, 10, 8, 7, 7, 6, 5, 6, 7, 8,
7, 9, 10, 10, 6, 5, 8, 10, 4, 6, 7, 7, 10, 6, 10, 10, 7, 6, 3,
6, 7, 5, 7, 8, 9, 11, 10, 7, 8, 5, 6, 6, 7, 8, 5, 4, 8, 8, 8,
7, 9, 5, 4, 4, 6, 5, 7, 8, 3, 9, 8, 8, 7, 5, 7, 4, 5, 5, 4, 6,
8, 8, 6, 7, 8, 4, 2, 4, 4, 3, 6, 7, 8, 9, 8, 7, 6, 4, 2, 3, 3,
3, 0, 1, 4, 6, 4, 2, 0, 9, 9, 10, 8, 10, 9, 7, 9, 6, 5, 9, 7,
6, 2, 2, 3, 5, 7, 8, 9, 9, 8, 7, 8, 1, 0, 3, 2, 2, 5, 3, 5, 8,
6, 6, 6, 8, 6, 2, 3, 4, 5, 7, 6, 7, 8, 3, 3),
A = rep(c(2, 5, 4, 4, 2, 3, 3, 5, 9, 3, 7, 2, 11), each=12),
B = factor(rep(1:2, each=6)),
C = factor(1:6),
ID = factor(rep(1:13, each=12))
)
options(contrasts=c("contr.sum","contr.poly")) # for Type III car::Anova
这是我的模型,我注意到 B:C 交互的差异。
m1 <- lmer(Y ~ A * B * C + (1|ID), data=d)
I 型方差分析(来自lmerTest),除了 A:B:C 之外,B:C 相互作用最后,给出 B:C 的 p=0.04。(但是,顺序似乎并不重要。)
anova(m1, type=1, ddf="Kenward-Roger")
#> Analysis of Variance Table of type I with Kenward-Roger
#> approximation for degrees of freedom
#> Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
#> A 8.794 8.794 1 11 2.908 0.11621
#> B 136.641 136.641 1 121 45.178 6.269e-10 ***
#> C 14.128 2.826 5 121 0.934 0.46141
#> A:B 0.381 0.381 1 121 0.126 0.72330
#> A:C 45.874 9.175 5 121 3.034 0.01291 *
#> B:C 34.821 6.964 5 121 2.303 0.04882 *
#> A:B:C 21.860 4.372 5 121 1.446 0.21285
包装中的II 型 Anovacar给出了相同的结果。
Anova(m1, type=2, test="F")
#> Analysis of Deviance Table (Type II Wald F tests with Kenward-Roger df)
#>
#> Response: Y
#> F Df Df.res Pr(>F)
#> A 2.9075 1 11 0.11621
#> B 45.1784 1 121 6.269e-10 ***
#> C 0.9343 5 121 0.46141
#> A:B 0.1259 1 121 0.72330
#> A:C 3.0335 5 121 0.01291 *
#> B:C 2.3026 5 121 0.04882 *
#> A:B:C 1.4456 5 121 0.21285
来自 的 II 型 Anova lmerTest,对于 B:C 给出 p=0.88,并且在 和 中都lmerTest与III 型相同car。
anova(m1, type=2, ddf="Kenward-Roger")
#> Analysis of Variance Table of type II with Kenward-Roger
#> approximation for degrees of freedom
#> Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
#> A 8.794 8.794 1 11 2.9075 0.1162113
#> B 41.500 41.500 1 121 13.7214 0.0003209 ***
#> C 50.879 10.176 5 121 3.3645 0.0070072 **
#> A:B 0.381 0.381 1 121 0.1259 0.7233027
#> A:C 45.874 9.175 5 121 3.0335 0.0129149 *
#> B:C 5.174 1.035 5 121 0.3422 0.8864025
#> A:B:C 21.860 4.372 5 121 1.4456 0.2128521
Anova(m1, type=3, test="F")
#> Analysis of Deviance Table (Type III Wald F tests with Kenward-Roger df)
#>
#> Response: Y
#> F Df Df.res Pr(>F)
#> (Intercept) 88.2434 1 11 1.376e-06 ***
#> A 2.9075 1 11 0.1162113
#> B 13.7214 1 121 0.0003209 ***
#> C 3.3645 5 121 0.0070072 **
#> A:B 0.1259 1 121 0.7233027
#> A:C 3.0335 5 121 0.0129149 *
#> B:C 0.3422 5 121 0.8864025
#> A:B:C 1.4456 5 121 0.2128521
anova(m1, type=3, ddf="Kenward-Roger")
#> Analysis of Variance Table of type III with Kenward-Roger
#> approximation for degrees of freedom
#> Sum Sq Mean Sq NumDF DenDF F.value Pr(>F)
#> A 8.794 8.794 1 11 2.9075 0.1162113
#> B 41.500 41.500 1 121 13.7214 0.0003209 ***
#> C 50.879 10.176 5 121 3.3645 0.0070072 **
#> A:B 0.381 0.381 1 121 0.1259 0.7233027
#> A:C 45.874 9.175 5 121 3.0335 0.0129149 *
#> B:C 5.174 1.035 5 121 0.3422 0.8864025
#> A:B:C 21.860 4.372 5 121 1.4456 0.2128521