I have a dataset with 300 individuals $i$ that provided ratings on objects $o$ that are $y_{io}$. Each individual rated a random sample of 3 objects out of 20 possible objects so that I have 900 observations. I think this would be called a partial cross-classified mixed model.

My basic equation is $$y_{io} = 1 + u_i + v_o + \varepsilon_{io}$$ I have a fixed intercept, a random intercept for individuals and a random intercept for objects.

I understand that the lme4 command for this would be:

fit <- lmer(y ~ 1 + (1 | i) + (1 | o), data = dta)

However, I also have some individual specific variables $X_i$ and some object specific variables $Z_o$. In addition, I have some additional variables from each individual about each rated object $W_{io}$.

First, I want to explain the random intercepts $u_i$ and $v_o$ with my individual and object specific variables:

$$u_i = 1 + \beta X_i + \phi_i$$ $$v_o = 1 + \gamma Z_o + \zeta_o$$

How do I set this up in lme4? My intuition would be to simply add them as fixed effects. Then the $\phi_i$ and $\zeta_o$ would replace the $u_i$ and $v_o$. Is that correct?

fit <- lmer(y ~ 1 + X + Z + (1 | i) + (1 | o), data = dta)

Or do I have to add them within the brackets?

How would I assess the explained variance in the second-level equations? Is that the reduction in variance of the random effect due to the inclusion of the predictors?

And how do I deal with the $W_{io}$. What would be a correct place for them conceptually and within the lme4 framework?


closed as off-topic by mkt, Michael Chernick, user158565, Peter Flom Aug 9 at 11:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because EITHER it is not about statistics, machine learning, data analysis, data mining, or data visualization, OR it focuses on programming, debugging, or performing routine operations within a statistical computing platform. If the latter, you could try the support links we maintain." – mkt, Michael Chernick, Peter Flom
If this question can be reworded to fit the rules in the help center, please edit the question.


Indeed, you can simply include these covariates in the formula of lmer() as

fit <- lmer(y ~ x + z + w + (1 | i) + (1 | o), data = dta) 

and you will get the estimates for their effects. In particular, the model that you will fit is $$y_{io} = \beta_0 + \beta_1 X_i + \beta_2 Z_o + \beta_3 W_{io} + u_i + v_o+ \varepsilon_{io},$$ with $u_i \sim \mathcal N(0, \sigma_u^2)$, $v_o \sim \mathcal N(0, \sigma_v^2)$, and $\varepsilon_{io} \sim \mathcal N(0, \sigma^2)$.

The change is the variance components $\sigma_u^2$, $\sigma_v^2$ and $\sigma^2$ when you include the covariates $X_i$, $Z_o$ and $W_{io}$ will indicate the variance explained by these predictors.

  • $\begingroup$ Thank you for your explanaition. $\endgroup$ – Jan-Michael Aug 9 at 14:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.