lme4 upgrade produces error message even after grouping variables within the data frame

后端 未结 1 1293
囚心锁ツ
囚心锁ツ 2021-01-26 09:45

I\'ve been running linear mixed models using an old version of lme4. Now that I have updated lme4 I\'m getting the following error:

Error en [[<-

相关标签:
1条回答
  • 2021-01-26 10:19

    This is indeed an as-yet-unfixed bug in lme4: https://github.com/lme4/lme4/issues/156 . However, the workaround is easy: just do conversions such as as.factor() and as.numeric() within the data frame, rather than within the formula, e.g.

    d.sdg.ngb = transform(d.sdg.ngb,species=factor(species))
    msdgtot = glmer(sdg.dens ~ ngbr.trees + (1 + ngbr.trees | species),
        data=d.sdg.ngb,family=poisson)
    

    in general, I think this should not even be necessary -- at least recent versions of glmer automatically convert grouping variables such as species to factors -- but I can appreciate wanting to be careful/explicit. If for some reason I don't want to permanently convert the grouping variable to a factor, I usually make a factor version of the variable, e.g.

    d.sdg.ngb = transform(d.sdg.ngb,fspecies=factor(species))
    

    and then use fspecies rather than species in the formula.

    For what it's worth, this would have been a problem in previously released versions of lme4 as well: with lme4.0 (the backward-compatible version),

    gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | herd),
      data=cbpp,family=binomial)
    

    works fine but

    gm1 <- glmer(cbind(incidence, size - incidence) ~ period + (1 | factor(herd)),
    data=cbpp,family=binomial)
    

    gives Error in factor(herd) : object 'herd' not found (admittedly a less cryptic error message, but still an error).

    0 讨论(0)
提交回复
热议问题