เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

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.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Hierarchical and Mixed Effects Models in R

ดูคอร์ส

คำแนะนำการฝึกหัด

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

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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)
แก้ไขและรันโค้ด