[R] formula in lmer including both nested and crossed effects

Douglas Bates bates at stat.wisc.edu
Wed Nov 19 21:04:55 CET 2008


On Wed, Nov 19, 2008 at 1:37 PM, Eduardo G. Martins <egmartins at gmail.com> wrote:
> Dear all,

> I was wondering if someone could help me with the specification of a
> formula including both nested and crossed effects in the same model in
> lmer. I have one predictor variable, x, and three grouping factors,
> a,b and c. Factor b is nested in a but is partially crossed with c.
> Also, I'm interested in an interaction between the crossed effects b
> and c. I specified a formula in lmer as

> y ~ x + (1|a/b) + (1|c) + (1|b:c)

> I could fit this model using lmer with no problems but I just would
> like to know if that specification is correct. Thank you so much for
> any thoughts.

That formula describes a model with the characteristics you describe
unless the levels of b are implicitly nested.  In other words, do the
levels of the factor b correspond to different experimental units by
themselves or only when considered within a level of a?  If different
levels correspond to different experimental units, so that there must
be more levels of b than of a, then (1|a/b), which expands to (1|a) +
(1|a:b), is equivalent to (1|a) + (1|b) and the formula makes sense
but I would prefer the more explicit

y ~ x + (1|a) + (1|b) + (1|c) + (1|b:c)

If the levels of b are only meaningful within levels of a then the
term (1|b:c) is not meaningful because b is not meaningful except in
conjunction with a.

It might help if you explained your experiment in more detail.  One
message to the group will probably suffice, though.  I received 3
copies of your original message.

More detail on implicit nesting is available in the part of the slides
at http://www.stat.wisc.edu/~bates/UseR2008/WorkshopD.pdf that discuss
an analysis of the Pastes data (slides 43 to 56).



More information about the R-help mailing list