1. Learn
  2. /
  3. Courses
  4. /
  5. Hierarchical and Mixed Effects Models in R

Connected

Exercise

Rescaling slopes

The last plot showed changes in crime rate varied by county. This shows you that you should include Year as both a random- and fixed-effect in your model. Including Year this way will estimate a global slope across all counties as well as slope for each county. The fixed-effect slope estimates the change in major crimes across all Maryland counties. The random-effect slope estimates model for that counties have different changes in crime.

But, fitting this model produces a warning message! To address this warning, change Year from starting at 2006 to starting at 0. We provide you with this new variable, Year2 (e.g., 2006 in Year is 0 in Year2). Sometimes when fitting regression, you need to scale or center the intercept to start at 0. This improves numerical stability of the model.

Instructions

100 XP
  • Build a lmer() to predict Crime with Year as both a fixed-effect and random-effect slope and County as the random-effect intercept.
  • Build a second lmer() to predict Crime with Year2 as both a fixed-effect and random-effect slope and County as the random-effect intercept.