On Apr 24, 2005, at 8:52 AM, Douglas Bates wrote:
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)
Thanks for the prompt reply. I tried what you suggested, here's what I got:
> turf.lme=lmer(dry_matter~compacting*variety+(1|rep)+(1|rc)+(1|rv), turf.data)
Error in lmer(dry_matter ~ compacting * variety + (1 | rep) + (1 | rc) + :
entry 3 in matrix[9,2] has row 3 and column 2
Just to see what the problem was, I deleted the third random term, and it didn't complain:
> turf.lme=lmer(dry_matter~compacting*variety+(1|rep)+(1|rv), turf.data) > anova(turf.lme) Analysis of Variance Table Df Sum Sq Mean Sq Denom F value Pr(>F) compacting 5 10.925 2.185 36.000 18.166 5.68e-09 *** variety 2 2.518 1.259 36.000 10.468 0.0002610 *** compacting:variety 10 6.042 0.604 36.000 5.023 0.0001461 ***
Now obviously this isn't a valid result since I need that third term; but interestingly, it didn't matter which term I deleted, so long as there were only two random terms. Any ideas as to what the error message is referring to?
Thanks for the help,
Jake Michaelson
______________________________________________ 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