R:线性混合效应模型的后期比较



我在线性混合效果模型的后期比较中遇到了一个问题。我将尝试用一个快速构建的不完美示例来解释它:

下面是我的示例数据:

Variable<-as.factor(rep(c(1,2,3),5))
Random<-rep(c(1,2,2),5)
Result<-rnorm(15,mean=10,sd=2)
Data<-as.data.frame(cbind(Variable,Random,Result))

我的模型中实际上包含了几个固定和随机的效果,但这足以说明我的问题:

library(lme4)
LME=lmer(Result~Variable+(1|Random))
summary(LME)

查看固定效果输出,我只得到与Intercept

相比变量的不同级别的显著性
Fixed effects:
Estimate Std. Error      df t value Pr(>|t|)    
(Intercept)   9.5104     1.3685 12.0000   6.949 1.54e-05 ***
Variable2     0.9155     1.9354 12.0000   0.473    0.645    
Variable3     1.7386     1.9354 12.0000   0.898    0.387    

然而,我现在想比较变量级别1与级别2和变量级别2与级别3,所以我尝试了以下操作:

library(multcomp)
summary(glht(LME, linfct=c("Variable2-Variable1=0","Variable3-Variable2=0")))

留给我这个错误:

Error in h(simpleError(msg, call)) : 
error in evaluating the argument 'object' in selecting a method for function 'summary': multcomp:::chrlinfct2matrix: variable(s) ‘Variable1’ not found

如果我排除变量级别1,只看2和3的比较,代码工作得很好:

summary(glht(LME, linfct=c("Variable3-Variable2=0")))
Simultaneous Tests for General Linear Hypotheses
Fit: lmer(formula = Result ~ Variable + (1 | Random))
Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
Variable3 - Variable2 == 0   0.8231     1.6694   0.493    0.622
(Adjusted p values reported -- single-step method)

我还可以运行linfct函数与Tukey对比:

summary(glht(LME, linfct= mcp(Variable="Tukey")),test=adjusted("none"))
Simultaneous Tests for General Linear Hypotheses
Multiple Comparisons of Means: Tukey Contrasts

Fit: lmer(formula = Result ~ Variable + (1 | Random))
Linear Hypotheses:
Estimate Std. Error z value Pr(>|z|)
2 - 1 == 0   0.9155     1.9354   0.473    0.636
3 - 1 == 0   1.7386     1.9354   0.898    0.369
3 - 2 == 0   0.8231     1.6694   0.493    0.622
(Adjusted p values reported -- none method)

看到我对3和1的比较不感兴趣,我只会使用其他2个p值,并在单独的步骤中调整它们,但这并不是我真正想要的解决方案。我的数据结果不仅仅是这里显示的两种比较,所以带有Tukey对比的选项会给我留下很多我并不真正感兴趣的比较。

有办法从LME得到Variable1吗?在固定效果中,它被包括为拦截,用Intercept代替Variable1或我能想到的任何组合都没有做到这一点。或者是否有更好的方法来实现我所寻找的比较?

任何帮助都将非常感激!

你真的已经得到了你想要的。在这种情况下,由于Variable=1是参考组,所以它的系数固定为0,方差为0。所以,Variable1=Variable2=0的测试是否真的只是Variable2=0的测试。同样与Variable3。您可以从以下两段代码产生相同的输出中看出这一点:

summary(glht(LME, linfct=c("Variable2=0","Variable3=0", "Variable3-Variable2=0")))
# Simultaneous Tests for General Linear Hypotheses
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#                            Estimate Std. Error z value Pr(>|z|)
# Variable2 == 0              -0.6524     2.0145  -0.324    0.942
# Variable3 == 0              -2.0845     2.0145  -1.035    0.545
# Variable3 - Variable2 == 0  -1.4321     1.1199  -1.279    0.396
# (Adjusted p values reported -- single-step method)
summary(glht(LME, linfct=mcp(Variable="Tukey")))
# Simultaneous Tests for General Linear Hypotheses
# Multiple Comparisons of Means: Tukey Contrasts
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#            Estimate Std. Error z value Pr(>|z|)
# 2 - 1 == 0  -0.6524     2.0145  -0.324    0.942
# 3 - 1 == 0  -2.0845     2.0145  -1.035    0.545
# 3 - 2 == 0  -1.4321     1.1199  -1.279    0.396
# (Adjusted p values reported -- single-step method)

所以,如果你只想与引用进行调整后的比较,你可以这样做:

summary(glht(LME, linfct=c("Variable2=0","Variable3=0")))
# Simultaneous Tests for General Linear Hypotheses
# Fit: lmer(formula = Result ~ Variable + (1 | Random))
# Linear Hypotheses:
#                Estimate Std. Error z value Pr(>|z|)
# Variable2 == 0  -0.6524     2.0145  -0.324    0.889
# Variable3 == 0  -2.0845     2.0145  -1.035    0.404
# (Adjusted p values reported -- single-step method)

最新更新