[R-sig-ME] lme4 error: "Number of levels of a grouping factor . . ."

Brent Pedersen bpederse at gmail.com
Wed Jul 27 21:15:32 CEST 2011


On Wed, Jul 27, 2011 at 12:10 PM, Ben Bolker <bbolker at gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On 07/27/2011 01:50 PM, Brent Pedersen wrote:
>> On Wed, Jul 27, 2011 at 7:34 AM, Ben Bolker <bbolker at gmail.com> wrote:
>> On 07/27/2011 03:29 AM, Martin Maechler wrote:
>>>>>>>>>> Gabrielle Miller-Messner <gmessner at ucdavis.edu>
>>>>>>>>>>     on Tue, 26 Jul 2011 22:26:38 -0700 writes:
>>>>>
>>>>>     > Hello, I have count/proportion data and I am trying to
>>>>>     > account for overdispersion in a logistic regression. With
>>>>>     > the following code from lme4 I receive the following error
>>>>>     > message:
>>>>>
>>>>>     >> glmm = glmer(cbind(fertilized, unfert) ~ density.class +
>>>>>     >                (1|individual), family = binomial)
>>>>>     > Number of levels of a grouping factor for the random effects
>>>>>     > is *equal* to n, the number of > observations
>>>>>
>>>>>     > This problem was mentioned in Warton and Hui 2011, so I
>>>>>     > imagine it may have been fixed recently.  I downloaded the
>>>>>     > most recent version of lme4 available through the command
>>>>>     > install.packages("lme4").  Is there an updated version of
>>>>>     > the package available in a different form?
>>>>>
>>>>> {yes, lme4a on R-forge, but that's not the issue now, and not
>>>>>  something I'd recommend to get into just right now ...}
>>>>>
>>>>> Well, I'm puzzled that you say you get an *error* with the above
>>>>> message.
>>>>> You should get a message, but no error in the case of glmer().
>>
>>  Probably this is indeed just a warning message and not an error?
>>   Gabrielle, does the function return an answer (i.e. a fitted model)?
>>
>>
>>> Hi, I've hit this as well. with:
>>
>> packageVersion("lme4a")
>>> [1]  0.999375.67
>>
>>> (should I be using another version?)
>>> and code:
>>
>>> """
>>> library(lme4a)
>>
>>> d = data.frame(a=runif(200),
>>>                b=sample(c(strsplit("ABCDEF", "")[[1]]), 200, replace=T),
>>>                c=as.factor(1:200))
>>> # d$c[2] = d$c[1]
>>
>>> fm = glmer(a ~ b + (1|c), d)
>>> """
>>> it shows:
>>> """
>>> Error in lmer(formula = a ~ b + (1 | c), data = d) :
>>>   number of levels of each grouping factor must be less than number of obs
>>> """
>>
>>> and if i uncomment that line to make the number of grouping factors (c) less
>>> than the number of obs, it runs successfully.
>>> not sure if this is different for binomial...
>
>
>
>  This is different because (despite using the function "glmer" and not
> "lmer"), you are actually fitting a linear mixed model (LMM) and not a
> generalized linear mixed model (GLMM) here.  (If you don't specify a
> family, or you specify a gaussian family with an identity link, glmer
> automatically reverts to calling lmer -- this is a design decision
> (infelicity?) that I hope we will get around to reversing ...)  In the
> case of a LMM, it doesn't make sense to fit a separate individual-level
> random factor, because it is completely confounded with the residual
> error.  You only need to worry about overdispersion, and hence it only
> makes sense to fit individual-level random effects, in cases where the
> scale parameter is fixed (e.g. binomial, Poisson).
>
>   Ben Bolker


that makes sense.
thanks.


>>
>>
>>>>>
>>>>>
>>>>> Just to be sure:  What does
>>>>>      packageVersion("lme4")
>>>>> say for you?
>>>>>
>>>>> Martin
>>>>>
>>>>>
>>>>>     > I am using R version 2.13.1 on OS 10.6.4.
>>>>>
>>>>>     > thank you!  Gabrielle
>>>>>
>>>>>     > --
>>>>>     > Gabrielle Miller-Messner Graduate Student Center for
>>>>>     > Population Biology Section of Evolution and Ecology
>>>>>     > University of California, Davis 1 Shields Avenue Davis,
>>>>>     > California 95616 gmessner at ucdavis.edu
>>>>>
>>>>>     >         [[alternative HTML version deleted]]
>>>>>
>>>>>     > _______________________________________________
>>>>>     > R-sig-mixed-models at r-project.org mailing list
>>>>>     > https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>>>>
>>>>> _______________________________________________
>>>>> R-sig-mixed-models at r-project.org mailing list
>>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>
>>>
> _______________________________________________
> R-sig-mixed-models at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
>>>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk4wVJwACgkQc5UpGjwzenOe5gCfRy8EeieSVwXSxbqnVKTS1E79
> VeIAn3z4QqAvAD1lxYCFHrzFWlHX6qkH
> =Ckg5
> -----END PGP SIGNATURE-----
>




More information about the R-sig-mixed-models mailing list