[R] linear mixed model with nested factors
Ben Bolker
bbolker at gmail.com
Tue Mar 8 03:12:19 CET 2011
David Dudek <david.dudek <at> student.umb.no> writes:
>
> Hi R-help.
>
> I am trying to run a linear mixed model with nested factors with either
> lme or lmer and I am having no luck obtaining the same results as Minitab.
> Here is Minitab's code:
>
> MTB > GLM 'count' = site year replicate(site year) site*year;
> SUBC> Random 'year' 'replicate';
>
> Can you tell me how to code this in R?
Guessing:
lmer(count~site+(site|year)+(1|replicate:site:year),data=...)
This assumes
(1) you're willing to treat your data as normally distributed
(see previous comments)
(2) you really have multiple samples within each value of 'replicate'
(otherwise 'replicate' will be confounded with your residual error)
(3) every site is measured in more than one year (most or all years
if you want decent power)
I'm having a bit of a hard time figuring out what you want
to do with 'replicate'. Are replicates coded uniquely, or within
sites? If you have multiple samples per replicate, and they are
strictly nested, it will probably be easiest to take the averages
for each replicate -- then your model would reduce to
avgcount~site+(site|year), and the residual error would be
the among-replicate within site-year variation.
More information about the R-help
mailing list