Model comparison with ANOVA
Comparing models can be difficult. Many methods exist although these are beyond the scope of this course such as model selection (e.g., AIC).
Analysis of Variance (ANOVA) exists as a basic option to compare lmer
models.
The ANOVA tests to see if one model explains more variability than a second model.
The ANOVA does this by examining the amount of variability explained by the models.
For example, you can see if Year
predicts Crime
in Maryland.
To do this, 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).
Cet exercice fait partie du cours
Hierarchical and Mixed Effects Models in R
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Build the Null model with only County as a random-effect
null_model <- lmer(Crime ~ (1 | ___) , 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 ~ ___ + (1 + ___ | ___) , data = md_crime)
# Compare null_model and year_model using an anova
anova(___, ___)