[R] Partially crossed and nested random factors in lme/lmer
Spencer Graves
spencer.graves at pdf.com
Wed Apr 26 12:11:52 CEST 2006
1. Are you familiar with Pinheiro and Bates (2000) Mixed-Effects
Models in S and S-Plus (Springer)? I've learned a lot from this book
both about mixed models generally and about "lme" in particular -- and
even indirectly about "lmer". Examples in this book would, I believe,
help you figure out how to get what you want from "lme". Files
containing virtually all the R commands in that book can be found in
"~\library\nlme\scripts" in your R installation directory. You can make
a local copy and walk through the code line by line, trying various
modifications as you go.
2. Are you familiar both with Doug Bates' recent article on mixed
models in R News and with his "mlmRev" package and "MlmSoftRev"
vignette? You can get an R script file of virtually all the R commands
in the *.PDF file accompanying the vignette, which you can then modify
as you wish to help you learn from the vignette. Examples in the
"vignette" help file tell you how to do this. [If you use XEmacs, the
"edit(v1)" line there may not work. Instead, try "Stangle(v1$file)"
then look for a new *.R file in your working directory -- identified by
getwd().]
If you've spent some time with both of these and still would like
further help from this group, please submit another post -- after first
reading the posting guide! "www.R-project.org/posting-guide.html",
especially the bit about providing a self-contained example. Many
different things might contribute to the problem you describe that "the
program terminates" with the second lmer example. I tried copying your
script into R and got, 'object "duration.root.transf" not found' from
both "lmer" and "lme". If your example had been self-contained -- and
the simpler the better -- I might have been able to help more.
hope this helps,
spencer graves
Corsin Müller, Zoologisches Inst. wrote:
> Hi all,
>
> I am not a very proficient R-user yet, so I hope I am not wasting people’s
> time. I want to run a linear mixed model with 3 random factors (A, B, C)
> where A and B are partially crossed and C is nested within B. I understand
> that this is not easily possible using lme but it might be using lmer. I
> encountered two problems when trying:
>
> Firstly, I can enter two random factors in lmer but I do not get complete
> outputs using both anova () and summary (). For instance, I only get df, SS,
> and MS using anova(). Even so the model runs without giving an error
> message.
>
>
>>lmer.inspection <- lmer(
duration.root.transf~
sex*sample.sex+age+sample.age+sample.type+
first.bout+location+sample.source +
(1|acceptor.grp) + (1|donor.grp))
>>anova (lmer.inspection)
>
> Analysis of Variance Table
> Df Sum Sq Mean Sq
> sex 1 0.06653 0.06653
> sample.sex 1 0.60389 0.60389
> …
>
> Running the same model in lme using only one random factor works fine.
>
>
>>lme.inspection <- lme(
duration.root.transf~
sex*sample.sex+age+sample.age+sample.type+
first.bout+location+sample.source, random=~1|acceptor.grp)
>>anova (lme.inspection)
>
> numDF denDF F-value p-value
> (Intercept) 1 4427 47690.12 <.0001
> sex 1 4427 7.93 0.0049
> sample.sex 1 4427 65.71 <.0001
> …
>
> Running the example given in “?lmer” also does not give a complete anova
> table. However, the example discussed in the email by Jacob Michaelson on
> the 24th of April 2005 “[R] random interactions in lme” gives a complete
> output. So I seem to miss out on something.
>
> Secondly, I am at a loss with how I can enter the third random factor, which
> should be nested within acceptor.grp. When trying the to me intuitively
> sensible
>
>
>>lmer.inspection <- lmer(duration.root.transf~ … + (1|acceptor.grp/id) + (1|donor.grp))
>
> the program terminates
>
> I am grateful for any suggestions.
>
> Version used: R 2.2.1 for Windows
>
> Thanks,
> Corsin Mueller
>
> ________________________________________
>
> Corsin Mueller
> Universität of Zuerich
> Zoological Institute
> Winterthurerstr. 190
> 8057 Zuerich
> Switzerland
>
> fon +41-(0)44-63 55277
> fax +41-(0)44-63 55490
> email corsin at zool.unizh.ch
>
> ______________________________________________
> R-help at 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
More information about the R-help
mailing list