如何使用lme4将没有随机效应的模型与具有随机效应的模型进行比较? [英] How to compare a model with no random effects to a model with a random effect using lme4?

查看:220
本文介绍了如何使用lme4将没有随机效应的模型与具有随机效应的模型进行比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用nlme包中的gls()来构建mod1,而不会产生随机影响. 然后,我可以将使用AIC的mod1与使用包含随机效果的lme()构建的mod2进行比较.

I can use gls() from the nlme package to build mod1 with no random effects. I can then compare mod1 using AIC to mod2 built using lme() which does include a random effect.

mod1 = gls(response ~ fixed1 + fixed2, method="REML", data)
mod2 = lme(response ~ fixed1 + fixed2, random = ~1 | random1, method="REML",data)
AIC(mod1,mod2)

lme4软件包是否有类似于gls()的东西,可以让我构建没有随机效果的mod3,并将其与使用包含随机效果的lmer()构建的mod4进行比较?

Is there something similar to gls() for the lme4 package which would allow me to build mod3 with no random effects and compare it to mod4 built using lmer() which does include a random effect?

mod3 = ???(response ~ fixed1 + fixed2, REML=T, data)
mod4 = lmer(response ~ fixed1 + fixed2 + (1|random1), REML=T, data)
AIC(mod3,mod4)

推荐答案

使用lme4的现代(> 1.0)版本,您可以直接比较lmer拟合和相应的lm模型但是,您必须使用ML ---对于没有随机效应的模型,很难为"REML准则"找到一个明智的类似物(因为这将涉及设置所有变量的数据的线性变换).固定效果为零...)

With modern (>1.0) versions of lme4 you can make a direct comparison between lmer fits and the corresponding lm model, but you have to use ML --- it's hard to come up with a sensible analogue of the "REML criterion" for a model without random effects (because it would involve a linear transformation of the data that set all of the fixed effects to zero ...)

您应该意识到,在具有和不具有方差成分的模型之间进行信息理论比较时,存在一些理论问题:请参见 GLMM常见问题解答以获取更多信息.

You should be aware that there are theoretical issues with information-theoretic comparisons between models with and without variance components: see the GLMM FAQ for more information.

library(lme4)
fm1 <- lmer(Reaction~Days+(1|Subject),sleepstudy, REML=FALSE)
fm0 <- lm(Reaction~Days,sleepstudy)
AIC(fm1,fm0)
##     df      AIC
## fm1  4 1802.079
## fm0  3 1906.293

我更喜欢这种格式的输出(增量AIC而不是原始AIC值):

I prefer output in this format (delta-AIC rather than raw AIC values):

bbmle::AICtab(fm1,fm0)
##     dAIC  df
## fm1   0.0 4 
## fm0 104.2 3 

为了进行测试,让我们模拟没有随机影响的数据(我不得不尝试几个随机数种子来获得一个示例,其中对象间std dev实际上估计为零):

To test, let's simulate data with no random effect (I had to try a couple of random-number seeds to get an example where the among-subject std dev was actually estimated as zero):

rr <- simulate(~Days+(1|Subject),
               newparams=list(theta=0,beta=fixef(fm1),
                         sigma=sigma(fm1)),
               newdata=sleepstudy,
               family="gaussian",
               seed=103)[[1]]
ss <- transform(sleepstudy,Reaction=rr)
fm1Z <- update(fm1,data=ss)
VarCorr(fm1Z)
##  Groups   Name        Std.Dev.
##  Subject  (Intercept)  0.000  
##  Residual             29.241
fm0Z <- update(fm0,data=ss)
all.equal(c(logLik(fm0Z)),c(logLik(fm1Z)))  ## TRUE

这篇关于如何使用lme4将没有随机效应的模型与具有随机效应的模型进行比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆