[R] modelling nested random effects with interactions in R
Lorenz.Gygax@fat.admin.ch
Lorenz.Gygax at fat.admin.ch
Fri Apr 2 07:40:50 CEST 2004
Hi Michael,
> I have a nested anova, with random factor "lakefac" nested within
> factor "fishfac" (fixed), with an additional fixed factor
> "Habfac". If I consider everything as fixed effects, it's addmittedly
> not the correct model, but I can at least get this to work:
> ...
> So now I try to run it using the lme4 package, treating
> lakefac as random;
I am not quite sure about lme4 but in limrary ('nlme') you would need to do
something like:
> lakernd < lme(ltotinv ~ habfac * fishfac,
random = ~ 1  fishfac/lakefac,
data= use)
with this model you have the fixed effect of habfac and fishfac and their
interaction, lme should get the df's of the model ok if you specify it that
way. In this way, the random term is only for the intercept (which to my
understanding is the same as saying there is no interaction between random
and fixed effects). If you want to include the interactions you need to do
something like this:
> lakernd.int < lme(ltotinv ~ habfac * fishfac,
random = ~ habfac * fishfac  fishfac/lakefac,
data= use)
Thus, you specify random effects for the habfac, fishfac and their
interactions, which is the same as saying that there are interactions
between random and fixed effects.
Possibly you might need to do something like the following (because fishfac
is in the fixed and the random term, thus you specify interactions
seperately for both levels:
> lakernd.int < lme(ltotinv ~ habfac * fishfac,
random = list (~ 1  fishfac,
~ habfac * fishfac  lakefac)
data= use)
To test whether interactions are significant you need to compare models.
Thus the following would test whether all these included interactions
togethter lead to a statistically better model:
anova (lakernd, lakernd.int)
I hope this helps to get you on the right track.
Regards, Lorenz

Lorenz Gygax
Tel: +41 (0)52 368 33 84 / lorenz.gygax at fat.admin.ch
Center for proper housing of ruminants and pigs
Swiss Veterinary Office
agroscope FAT Tänikon, CH8356 Ettenhausen / Switzerland
Fax : +41 (0)52 365 11 90 / Tel: +41 (0)52 368 31 31
More information about the Rhelp
mailing list