[R] model non-nested random effects in nlme library

Ben Bolker bbolker at gmail.com
Mon Jan 23 17:38:57 CET 2012


mwege <RProgStuff <at> gmail.com> writes:

> 
> Hello all,
> 
> In lme4 if you want to model two non-nested random effects you code it like
> this:
> 
> mod1 <- lmer(y~x + (1|randomvar1) + (1|randomvar2))
> 
> How would you go about to model something similar in nlme?
> 
> In my database I have two variables for which I have repeated measures, lets
> call them "individual" and "year".
> But none of the "individuals" were measured in more than one year. So as I
> understand it, I should not nest individual in year or visa versa.

  Not necessarily.  If you believed that there were good years and
bad years but individuals varied randomly within years (i.e. there
is no such thing as a consistently good individual) then you would
have individuals nested within years.  If you have at least some
multiple measurements of some individuals *within* some years,
then you have a three-level model (samples within individuals
within years, where the among-sample variance is the residual error);
otherwise you have a two-level model (individuals within years).

If you believe there are good individuals and bad individuals
but that years are not good or bad for everyone then you have
years nested within individuals.

  Otherwise you indeed have a crossed design.


>  Someone suggested I do it as above. But I am accustomed to nlme, and dont
> know how one would code non-nested random effects.
> 
> In the Pinheiro and Bates book there is an example coded like this:
> modB <- lme(y~x,
>   +   random = pdBlocked(list(pdIdent(~year-1), pdIdent(~individual-1))))
> 
> But when I try it I keep getting an error message saying:  "Error in
> getGroups.data.frame(dataMix, groups) : 
>   Invalid formula for groups"

  It would definitely be best to forward this question to the r-sig-mixed-models
<at> r-project.org mailing list ... (I'm answering via Gmane, otherwise
I would do it myself)

  Can you provide a reproducible example?



More information about the R-help mailing list