[R-sig-ME] formula random terms in lmer function

Ben Bolker bbolker at gmail.com
Thu Mar 6 19:01:14 CET 2014


On 14-03-06 10:23 AM, Senegaf wrote:
> Dear R-sig-mixed-models Group,
> 
> I am new in R and I would confirm my understanding of lmer function in lme4 via the example below: 
> 
> lmer(Y~(1|X)+(1|X:Y)+(1|Y:Z))
> 
> X is random
> The interaction between X and Y is random
> Z nested into Y is random
> 
> If so, should I unsderstand that interaction and nesting are similarly specified.

   See http://glmm.wikidot.com/faq#modelspec

  There are no fixed effects in this model (although there is an
implicit intercept term).

  X, X:Y, and Y:Z are *grouping variables*.  X, Y, and Z will be treated
as categorical variables (factors); if this doesn't make sense (e.g. if
one of them is a numeric covariate with unique values for every
observation), then the model doesn't make sense. All three random effect
terms in the model (anything with a | in it is a random effect term) are
*scalar, intercept* random effects -- that is, the baseline/mean values
varies randomly among groups defined by the levels of X, X:Y, and Y:Z.

  : denotes an interaction.

  You could say that Y is *nested* in X, and you could specify the model
equivalently as

  (1|X/Y) + (1|Y:Z)

  I really don't know what you're trying to do without more context, but
it *might* be that you want (1|X/Y/Z) (Z nested within Y within X), or
equivalently  (1|X) + (1|X:Y) + (1|X:Y:Z).

  Hope that helps.

  Ben Bolker



> 
> Grateful if someone could advise. Thank you!
> 
> Gaston



More information about the R-sig-mixed-models mailing list