Exercise

# Model comparison with ANOVA

Comparing models can be difficult and many methods exist that are beyond the scope of this course such as model selection (e.g., AIC). For example, including too many predictors can cause models to be overfit.

One tool you are likely familiar with, Analysis of Variance (ANOVA), can be used to compare two different `lmer`

models and test if one model explains more variability than the other model. Specifically, ANOVA can be used to test the amount of variability explained by `lmer`

models.

If you wanted to see if `Year`

is important for predicting `Crime`

in Maryland, we can build a null model with only `County`

as a random-effect and a year model that includes `Year`

. You can then compare the two models using the `anova()`

function.

If `Year`

explains a significant amount of variability, then the P-value will be less than your pre-specified threshold (usually 0.05).

Instructions 1/2

**undefined XP**

- Build a model that only includes
`County`

as a random-effect. - Build a model that includes
`Year2`

as a random-effect slope. - Compare
`null_model`

(first) to`year_model`

(second) using`anova()`

.