[R-sig-ME] number of random-effects levels

Ben Bolker bbolker at gmail.com
Wed Dec 5 04:56:25 CET 2012


Andrea Cantieni <andrea.cantieni at ...> writes:


> I am fitting a classroom data set with lmer() with completely nested
> data, i.e. pupils are nested within classes, and classes are nested
> within schools. I have read about the random effects levels:
> "...there must be a reasonable number of random-effects levels
> (e.g. blocks) — more than 5 or 6 at a minimum."
> (http://glmm.wikidot.com/faq).

> 
> The model looks like
> 
> fit0 <- lmer(theta ~ (1|CLASSID) + (1|SCHOOLID), data.ml)
> 
> and the contingency table looks like
> 
> xtabs(~ SCHOOLID, unique(subset(data.ml, select=c(SCHOOLID,CLASSID))))
> 
> SCHOOLID
> 1  2  3  5  6  7  8  9 10 12 13 14 15 16 
> 5  3  3  4  8  3  1  3  4  2  5  3  3  2 
 
> My question is, whether the reasonable number of random-effects
> levels of 5 or 6 means the total number of levels (i.e. 49 for
> CLASSID, and 14 for SCHOOLID) or the numbers of levels for CLASSID
> within SCHOOLID (i.e. 1 to 8 for CLASSID).

  It's the former; it's the number of random-effects values from which you're
trying to estimate the relevant variances.  Since you're assuming that
the variance of classes within schools is the same for all schools,
you have all 49 classes with which to estimate the variance.
If you were trying to fit a model where the variance itself varied
from school to school, you'd probably be in trouble, because then
you'd be trying to fit the variance from very small numbers of
samples (although you could imagine making the variance itself
a random effect that varied among schools ... but (a) this would
be a bit hard to specify in lmer [I would probably try BUGS for that
model] and (b) you might still have trouble because of lack of
data for this model -- my guess would be that you'd end up with
an estimate of zero among-school variation in variance ...)



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