[R] modelling nested random effects with interactions in R
Michael Rennie
mrennie at utm.utoronto.ca
Thu Apr 1 18:14:08 CEST 2004
Hi there
Please excuse this elementary question, but I have been fumbling with this for
hours and can't seem to get it right.
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:
> nested <- anova(lm(ltotinv ~ habfac + fishfac/lakefac + habfac:fishfac +
habfac:(lakefac %in% fishfac)))
> nested
Analysis of Variance Table
Response: ltotinv
Df Sum Sq Mean Sq F value Pr(>F)
habfac 2 17.3140 8.6570 25.0568 3.534e-08 ***
fishfac 1 0.9131 0.9131 2.6428 0.11057
fishfac:lakefac 2 2.3802 1.1901 3.4447 0.04000 *
habfac:fishfac 2 13.0101 6.5050 18.8281 9.196e-07 ***
habfac:fishfac:lakefac 4 3.0103 0.7526 2.1783 0.08557 .
Residuals 48 16.5838 0.3455
---
So now I try to run it using the lme4 package, treating lakefac as random;
>
> lakernd <- lme(ltotinv ~ habfac + fishfac/lakefac + habfac:fishfac + habfac:
(lakefac %in% fishfac), random = ~ lakefac)
Error in .class1(object) : Argument "data" is missing, with no default
> lakernd
Error: Object "lakernd" not found
The lme help file suggests that if "data" is not specified, that it defaults to
whatever object is currently in use in the environment (as was the case in the
fixed effects model- I am using a matrix called "use" in this example). If I
(naively) simply try to add data= use to the above formula, this happens:
> lakernd <- lme(ltotinv ~ habfac + fishfac/lakefac + habfac:fishfac + habfac:
(lakefac %in% fishfac), data = use, random = ~ lakefac)
Error in as(data, "data.frame") : No method or default for coercing "matrix"
to "data.frame"
So how do I get lme to use my data matrix "use" for the model? My guess is that
my syntax is off, but does anyone have any suggestions on how to fix it?
Unfortunately, the only resources I have available to me at the moment are
an "S-plus v. 4. guide to statistics", the archived help files on the R
website, an the examples and help files in R.
Your help with this problem is greatly appreciated- I do hope to hear from
someone as to how I might get this to work.
Sincerely,
--
Michael Rennie
Ph.D. Candidate
University of Toronto at Mississauga
3359 Mississauga Rd. N.
Mississauga ON L5L 1C6
Ph: 905-828-5452 Fax: 905-828-3792
More information about the R-help
mailing list