我正在做一些事后比较(在 lme4 中,但在这里我将只展示一个简单的线性模型),我很难确保我正在构建正确的对比矩阵来测试某些组合之间的差异因素。
这是我的模型:
dataset <- data.frame(response=rnorm(1200), factorX=rep(c("1", "2"), 600), factor2=rep(c("A", "B", "C"), 400))
model <- lm(response ~ factorX*factor2,data = dataset)
在我的数据集中,我根据两个因素测量了一个响应变量:factorX(有 2 个水平:1 和 2,1 是参考水平)和 factor2(有 3 个水平:A、B 和 C,A 是参考水平)。
我得到这个模型输出:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.02918 0.07183 0.406 0.685
factorX2 -0.03780 0.10158 -0.372 0.710
factor2B 0.02027 0.10158 0.200 0.842
factor2C -0.10972 0.10158 -1.080 0.280
factorX2:factor2B 0.01409 0.14366 0.098 0.922
factorX2:factor2C 0.08925 0.14366 0.621 0.535
问题:
我想知道某些因子水平组合之间是否存在显着差异,因此我建立了以下对比,并想知道它们是否对应于正确的比较:
c(0, 0, 0, 0, 0, 1)=> factorX1_factor2A 与 factorX2_factor2C
c(0, 0, 1, 0, -1, 0)=> factorX1_factor2B 与 factorX2_factor2B
c(0, -1, -1, 0, 0, 1)=> factorX2_factor2B 与 factorX2_factor2C
c(0, 0, 0, 1, 0, 0)=> factorX1_factor2A 与 factorX1_factor2C
c(0, 1, 0, 0, 0, 0)=> factorX1_factor2A 与 factorX2_factor2A
这是对的吗?!
谢谢!