[R] random interactions in lme
Douglas Bates
bates at stat.wisc.edu
Sun Apr 24 16:52:47 CEST 2005
Jacob Michaelson wrote:
> Hi All,
>
> I'm taking an Experimental Design course this semester, and have spent
> many long hours trying to coax the professor's SAS examples into
> something that will work in R (I'd prefer that the things I learn not be
> tied to a license). It's been a long semester in that regard.
>
> One thing that has really frustrated me is that lme has an extremely
> counterintuitive way for specifying random terms. I can usually figure
> out how to express a single random term, but if there are multiple terms
> or random interactions, the documentation available just doesn't hold up.
>
> Here's an example: a split block (strip plot) design evaluated in SAS
> with PROC MIXED (an excerpt of the model and random statements):
>
> model DryMatter = Compacting|Variety / outp = residuals ddfm =
> satterthwaite;
> random Rep Rep*Compacting Rep*Variety;
>
> Now the fixed part of that model is easy enough in lme:
> "DryMatter~Compacting*Variety"
> But I can't find anything that adequately explains how to simply add the
> random terms to the model, ie "rep + rep:compacting + rep:variety";
> anything to do with random terms in lme seems to go off about grouping
> factors, which just isn't intuitive for me.
The grouping factor is rep because the random effects are associated
with the levels of rep.
I don't always understand the SAS notation so you may need to help me
out here. Do you expect to get a single variance component estimate for
Rep*Compacting and a single variance component for Rep*Variety? If so,
you would specify the model in lmer by first creating factors for the
interaction of Rep and Compacting and the interaction of Rep and Variety.
dat$RepC <- with(dat, Rep:Compacting)[drop=TRUE]
dat$RepV <- with(dat, Rep:Variety)[drop=TRUE]
fm <- lmer(DryMatter ~ Compacting*Variety+(1|Rep)+(1|RepC)+(1|RepV), dat)
More information about the R-help
mailing list