CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Hierarchical and Mixed Effects Models in R

Afficher le cours

Instructions

  • 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.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Fit the model with Year as both a fixed and random-effect
lmer(___ ~ Year + (1 + Year | ___) , data = md_crime)

# Fit the model with Year2 rather than Year
lmer(___ ~ Year2 + (1 + Year2 | ___) , data = md_crime)
Modifier et exécuter le code