Hi,


> I'm wondering how to test for the significance of a single random-effect
> factor in lme4. For example, in the famous Rail example, I might want to
> know
> whether the identity of the rail makes any difference. The naive approach
> would be:
> > (a <- lmer( travel ~ (1|Rail) + 1, Rail ) )
> > (b <- lmer( travel ~ 1, Rail ) )
> > anova(a,b)
> but this doesn't work because the second line causes an error:
> > (b <- lmer( travel ~ 1, Rail ) )
> Error in lmerFactorList(formula, fr, 0L, 0L) :
>  No random effects terms specified in formula
>
> An alternative would be to use
> > (b <- lm( travel ~ 1, Rail ) )
> but then the anova function fails:
> > anova(a,b)
> Error in FUN(X[[1L]], ...) :
>  no slot of name "call" for this object of class "lm"
> (This case was already discussed in an earlier email to this list:
> https://stat.ethz.ch/pipermail/r-sig-mixed-models/2007q2/000197.html
> )
>

Using conventional likelihood ratio tests to test the significance of random
effects produces a very conservative test because the asymptotics are
different than for tests of fixed effects (the null hypothesis "variance =
0" is on the edge of the parameter space, which means trouble). Our package
RLRsim implements exact (restricted) likelihood ratio tests of random
effects in linear mixed models. Just use:

R> library(nlme)
R> data(Rail)
R> detach(package:nlme)
R> library(lme4)
R>* library(RLRsim)*
R> (a <- lmer( travel ~ (1|Rail) + 1, Rail ) )
R>* exactRLRT(a) *

to get the LRT-Statictis and the exact finite sample p-value for the random
intercept. You can also use RLRsim to test the significance of random
effects in linear mixed models with more than one random effect if the
tested effect is independent of the other random effects in the model (in
lme4: if they are not in the same bracket , e.g. calling exactRLRT on a
model with (x|factor) + (y|factor) should work, but (x+y|factor) won't.)
Setting up the test in more complex models is a bit cumbersome, feel free to
mail me off list if you run into trouble.

HTH,
Fabian

	[[alternative HTML version deleted]]


