How to compare a model with no random effects to a model with a random effect using lme4?

前端 未结 1 1044
眼角桃花
眼角桃花 2021-02-01 06:16

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.

相关标签:
1条回答
  • 2021-02-01 07:10

    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 ...)

    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
    

    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 
    

    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
    
    0 讨论(0)
提交回复
热议问题