compare variability explained by one model to the variability explained by the other
# Build the Null model with only County as a random-effect
null_model <- lmer(Crime ~ (1 | County) , data = md_crime)
# Build the Year2 model with Year2 as a fixed and random slope and County as the random-effect
year_model <- lmer(Crime ~ Year2 + (1 + Year2 | County) , data = md_crime)
# Compare null_model and year_model using an anova
anova(null_model, year_model)
deciding if random-effect intercept is required
plot the data
in this case, intercepts are different across the groups and a random-effect intercept is required
Hypothesis testing
Use lmerTest package which gives p-values (lmer4 does not)