kriggs
kriggs

Reputation: 11

understanding lmer random effects in R

What is the point of the "1 +" in (1 + X1|X2) structure of the random effect of an lmer function in lme4 package of R, and how does this differ from (1|X1) + (1|X2)?

Upvotes: 1

Views: 852

Answers (1)

Ben Bolker
Ben Bolker

Reputation: 226077

As the comment suggests, looking at the GLMM FAQ might be useful.

(1+X1|X2) is identical to (X1|X2) (due to R's default of adding an intercept). This fits a model where all of the effects of X1 (i.e. all of the predictors that we would get from a linear model using y ~ X1) vary across the groups/levels defined by X2, and all of the correlations among these varying effects are estimated.

  • if X1 is numeric, this fits a random-slopes model that estimates the variation in the intercept across groups, the variation in the slope across groups, and their covariance (correlation).
  • if X1 is categorical (a factor), this estimates variation based on the contrasts used for X1. Suppose X1 has three levels {A, B, C} and the default treatment contrasts are being used. Then a 3x3 covariance matrix is estimated which includes
    • the variation in the intercept (== the expected value in level A) across groups
    • the variation in the difference between A and B across groups
    • the variation in the difference between A and C across groups
    • all three pairwise covariances/correlations (A vs A-B, A vs A-C, A-B vs A-C)

The formula (1|X1) + (1|X2) only makes sense if X1 is categorical (only categorical variables, or variables that can be treated as categorical, make sense as grouping variables). This estimates the variation in the intercept (baseline response) among levels of X2 and the variation in the intercept (baseline response) among levels of X1.

As a final note, it's hard for me to think of a case where the latter formula ((1|X1) + (1|X2)) would make sense as an alternative to (X1|X2) ...

Upvotes: 3

Related Questions