18. Comparison of regression models
Often we wish to compare regression models that are nested in order to see if it was worthwhile adding a new predictor variable. Comparison of nested models is performed using the anova() function. For example, we might wish to see whether age can predict vo2max in our data, and then compare that to when age and gender are used as predictors. Let’s have a go. Make sure you put the more complex model first in the anova function.
fit_vo2max_age <- lm(vo2max ~ age, data = data)
summary(fit_vo2max_age)
fit_vo2max_age_gender <- lm(vo2max ~ age + gender, data = data)
summary(fit_vo2max_age_gender)
anova(fit_vo2max_age_gender, fit_vo2max_age)
Alternatively, the Likelihood-ratio test can be used via the lrtest function. However, this requires the “lmtest” and “zoo” (which lmtest depends upon) packages, so you will need to install them as described earlier for the doBy package. Make sure you put the more complex model first in the lrtest function.
Lrtest(fit_vo2max_age_gender, fit_vo2max_age)
Both comparisons clearly show that it was definitely worthwhile adding gender into the model.