[R-sig-ME] Creation of a dummy variable with Lme4

Ben Bolker bbolker at gmail.com
Fri Feb 28 18:59:40 CET 2014


On 14-02-28 12:07 PM, Camille Le Gall-Payne wrote:
>  
> 
> Hi Mr. Bolker, 
> 

[cc'ing to r-sig-mixed-models]


> I am having a little problem with the package lme4. I am trying to test
> the random structure of a GLMM model. With the previous version of the
> package I could create a dummy variable and perform a LRT test of the
> random structure. However, with the new version of lme4 the glmer
> function prevents us to use a random variable with only one level. 
> 
> I was wondering if there is a way to create a dummy variable with glmer
> ? or If you know of another way to test the random structure of a GLMM
> model ? 
> 
> Thank you, 
> 
> Have a nice day 
> 
> Camille 


  I hadn't seen this particular trick before, but I can see what you're
doing -- hopefully the dummy grouping variable you're creating here ends
up with an estimated variance of zero (otherwise I would worry about
whether your results are sensible or not).  You can use

 control=glmerControl(check.nlev.gtr.1="ignore")

in your glmer() call to override the error you would otherwise get.

  It's also worth considering that in lme4 > 1.0, the likelihood values
that are computed are commensurate with those returned by glm().  I
don't know offhand whether anova(m1,m0) (where m1 is a glmer fit/merMod
object and m0 is a glm fit/object) works, but there's no reason in
principle why it shouldn't.

   In principle you could also do this by extracting the deviance
function (dd <- update(m1,devFunOnly=TRUE)) and optimizing over the
fixed-effects parameters while holding the random-effects parameters at
0 (i.e. computing the profiled likelihood for zero random effects), but
this is really just a highly inefficient way to fit the same model that
you would get by leaving out the REs and using glm().

  Ben Bolker



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