我注意到,当使用包含因子类型预测变量的lmer
包中的lme4
函数指定模型时,指示预测变量级别的后缀是该因子的字符串等级,就像在这里治疗一样:
library(afex)
data(obk.long)
m1 <- lmer(value ~ treatment + (1|id), obk.long)
summary(m1)
Fixed effects:
Estimate Std. Error t value
(Intercept) 4.200 0.654 6.43
treatmentA 2.050 0.980 2.09
treatmentB 1.800 0.856 2.10
但是,在mixed
包中使用afex
函数时,后缀为数字:
m2 <- mixed(value ~ treatment + (1|id), obk.long)
summary(m2$full.model) # this should be the same as the lmer output... it's er, not
Fixed effects:
Estimate Std. Error t value
(Intercept) 5.483 0.375 14.62
treatment1 -1.283 0.532 -2.41
treatment2 0.767 0.565 1.36
有没有人知道导致预测标签级别后缀和/或固定效果差异的原因是什么?
答案 0 :(得分:4)
afex
默认情况下将分类预测变量的对比度编码设置为总和对比(当您使用mixed
时在消息中提及),而lmer
调用中指定的模型使用R的全局选项中的对比度设置。
options('contrasts')
##$contrasts
## unordered ordered
##"contr.treatment" "contr.poly"
obk2 <- obk.long
contrasts(obk2$treatment) <- "contr.sum"
# Or alternatively, set the global option with something like:
# options(contrasts=c('contr.sum', 'contr.poly'))
m_contr <- lmer(value ~ treatment + (1|id), obk2)
summary(m_contr)$coefficients # fixed effects only for brevity
## Estimate Std. Error t value
##(Intercept) 5.4833333 0.3751349 14.616966
##treatment1 -1.2833333 0.5321163 -2.411753
##treatment2 0.7666667 0.5645823 1.357936
all.equal(summary(m2)$coefficients, summary(m_contr)$coefficients)
##[1] TRUE