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.
Este ejercicio forma parte del curso
Hierarchical and Mixed Effects Models in R
Instrucciones del ejercicio
- Build a
lmer()
to predictCrime
withYear
as both a fixed-effect and random-effect slope andCounty
as the random-effect intercept. - Build a second
lmer()
to predictCrime
withYear2
as both a fixed-effect and random-effect slope andCounty
as the random-effect intercept.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# 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)