Exercise

Random-effect slopes

In the previous exercise, you saw how to code random-effect intercepts. You will now see how to code random-effect slopes. With lme4 syntax, lmer() uses (countinuous_predictor | random_effect_group) for a random-effect slope. When lme4 estimates a random-effect slope, it also estimates a random-effect intercept. scale() rescaled the predictor variable mathkind to make the model more numerically stable. Without this change, lmer() cannot fit the model.

In the previous exercise, you estimated a random-effect intercept for each classroom and one slope for all data. Here, you will estimate a random-effect intercept for each class and a random-effect slope for each classroom. Like a random-effect intercept, a random-effect slope comes from a shared distribution of all random-effect slopes.

Instructions 1/2

undefined XP
    1
    2
  • Run the existing code to rescale mathkind to be mathkind_scaled.
  • Use the lmer() function from the lme4 package to fit a random-effects intercept model. This is similar to the model you fit before, but has mathgain predicted by mathkind_scaled. classid is the random-effect. Use the student_data.
  • Use the lmer() function from the lme4 package to fit a random-effects slope model. mathgain is predicted by mathkind_scaled as a random-effect slope and classid as a random-effect group.