Re: [R] mixed model

From: Douglas Bates <bates_at_stat.wisc.edu>
Date: Thu 26 May 2005 - 02:06:27 EST

NATALIA F TCHETCHERINA wrote:
> Hello all,
> I have problem with setting up random effects.
> I have a model:
> y=x1+x2+x1*x2+z1+z1*x2
> where x1, x2, x1*x2 are fixed effects
> and z1, z1*x2 are random effects (crossed effects)
> I use library(nlme) 'lme' function.
> My question is: how I should set up random effects?
> I did
> lme(y~x1+x2+x1:x2, data=DATA, random=~z1+z1:x2, na.action='na.omit')
> but it did not work.
>
> Sincerely, Natalia.
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

The answer will depend on the types of x1, x2 and z1 (i.e. whether each of them is numeric or a factor). Because you use x1:x2 I will assume that x1, x2 and z1 are all factors. In that case the formula term x1*x2 is equivalent to x1 + x2 + x1:x2 and you could write the call to lme as

lme(y ~ x1*x2, data = DATA, random = ~1|z1/x1)

For lmer from the lme4 package it would be

lmer(y ~ x1*x2 + (1|z1) + (1|z1:x1), data = DATA)



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu May 26 02:16:35 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:05 EST