In this class we learned about the likelihood ratio test, sometimes called Wilk’s test. A basic requirement for this test is that one model is nested in the other. All we do is create two models, one more complicated than the other. We then take the log likelihood of the two models. We then define the test statistic as negative two times the difference in the likelihoods. Thus, the greater the difference between the likelihoods, the higher the test stat. The test stat will be compared to a chi squared distribution operating with the degrees of freedom equal to the difference in parameters in the two models. The null hypothesis is that the smaller model is a better fit, so a small p-value will lead us to reject the null in favor of the hypothesis that the larger model is a better fit. Now we can do a quick example to showcase this process.
library(alr3)
## Loading required package: car
## Loading required package: carData
data(ais)
attach(ais)
smallmod <- lm(Bfat ~ Ht)
bigmod <- lm(Bfat ~ Ht + Wt)
We’ve created two models, one predicting body fat percentage based on height, the other predicting body fat percentage on both height and weight.
logLik(smallmod)
## 'log Lik.' -650.7163 (df=3)
logLik(bigmod)
## 'log Lik.' -644.7727 (df=4)
mydf <- length(coef(bigmod)) - length(coef(smallmod))
Now we have the log likelihoods of the two models and the degrees of freedom for the chi squared distribution. Now we can find the test stat and the p-value.
(teststat<- -2*as.numeric(logLik(smallmod) - logLik(bigmod)))
## [1] 11.8873
pchisq(teststat, df = mydf, lower.tail = FALSE)
## [1] 0.0005651809
R tells us that our test statistic is 11.8873 and our p-value is less than .001. This means we reject the null hypothesis and conclude that the bigger model with both weight and height as predictors is better.