如何在混合效应模型中获得系数及其置信区间? [英] How to get coefficients and their confidence intervals in mixed effects models?
问题描述
在lm
和glm
模型中,我使用函数coef
和confint
达到目标:
In lm
and glm
models, I use functions coef
and confint
to achieve the goal:
m = lm(resp ~ 0 + var1 + var1:var2) # var1 categorical, var2 continuous
coef(m)
confint(m)
现在,我在模型中添加了随机效果-使用来自lme4包中的lmer
函数的混合效果模型.但是然后,功能coef
和confint
对我来说不再起作用了!
Now I added random effect to the model - used mixed effects models using lmer
function from lme4 package. But then, functions coef
and confint
do not work any more for me!
> mix1 = lmer(resp ~ 0 + var1 + var1:var2 + (1|var3))
# var1, var3 categorical, var2 continuous
> coef(mix1)
Error in coef(mix1) : unable to align random and fixed effects
> confint(mix1)
Error: $ operator not defined for this S4 class
我试图用google搜索并使用文档,但没有结果.请指出正确的方向.
I tried to google and use docs but with no result. Please point me in the right direction.
我也在想这个问题是否更适合 https://stats.stackexchange.com/,但我认为技术比统计更重要,所以我得出结论,它最适合这里(SO)...您怎么看?
I was also thinking whether this question fits more to https://stats.stackexchange.com/ but I consider it more technical than statistical, so I concluded it fits best here (SO)... what do you think?
推荐答案
有两个新程序包, lmerTest 和 lsmeans ,可以为lmer
和glmer
输出计算95%的置信度限制.也许您可以调查一下?而且 coefplot2 ,我认为也可以做到(尽管Ben在下面指出,而不是lmerTest
和lsmeans
中使用的Kenward-Roger和/或Satterthwaite df近似值,而不是Wald统计量的标准误差).软件包lsmeans
中的内置绘图功能(如软件包effects()
中的内容一样),btw还返回了lmer
和glmer
对象的95%置信度,但是通过在没有任何随机因素的情况下对模型进行了拟合来实现.显然是不正确的.
There are two new packages, lmerTest and lsmeans, that can calculate 95% confidence limits for lmer
and glmer
output. Maybe you can look into those? And coefplot2, I think can do it too (though as Ben points out below, in a not so sophisticated way, from the standard errors on the Wald statistics, as opposed to Kenward-Roger and/or Satterthwaite df approximations used in lmerTest
and lsmeans
)... Just a shame that there are still no inbuilt plotting facilities in package lsmeans
(as there are in package effects()
, which btw also returns 95% confidence limits on lmer
and glmer
objects but does so by refitting a model without any of the random factors, which is evidently not correct).
这篇关于如何在混合效应模型中获得系数及其置信区间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!