I'm confused about getting different results when trying to perform the likelihood ratio test (LRT) with R in different ways that are supposed to be equivalent. Below is the R code with some simulated data. I use GAM model with one predictor, whose significance I want to evaluate by comparing the models with and without that predictor.
As far as I know, the theory says the LRT statistic can be computed either from the log likelihoods of the original and the reduced models, or from their residual deviances, as both ways lead to identical calculations:
$$LRstatistic = Deviance_{reduced} - Deviance_{orig} \\ = -2×(logLik_{reduced}-logLik_{saturated}) + 2x(logLik_{orig}-logLik_{saturated}) \\ = -2×(logLik_{reduced} - logLik_{orig})$$
But in the example below, the LRT statistic computed from the log likelihoods (as provided by the logLik
function) is 17.7, while the same statistic computed from the residual deviances (as provided by the deviance
function) is 38555.7. It is way far from identical.
Moreover, when I perform the LRT test using the anova
function, it reports the same deviances and residual DF, but the final p value differs from either of the two manual calculations.
Could anyone give me some insight why I see those differences and which of the three ways is actually correct? Thanks in advance!
# data
set.seed(100)
pred <- runif(100)
resp <- 0.5*pred - 5*pred^2 - 50*pred^3 + rnorm(100, sd=50)
plot(pred, resp)
# model fit
m <- gam(resp~s(pred)) # original model
m.red <- update(m, ~.-s(pred)) # reduced model
# LRT using logLik
ll <- logLik(m) # log likelihood of the orig. model
npar <- attr(ll, "df") # number of estimated parameters in the orig. model
ll.red <- logLik(m.red) # log likelihood of the reduced model
npar.red <- attr(ll.red, "df") # number of estimated parameters in the reduced model
lrt <- -2*(ll.red[1] - ll[1]) # likelihood ratio statistic (17.7)
df <- npar - npar.red # degrees of freedom (3.2)
1-pchisq(lrt, df) # p value (0.0007)
# LRT using deviance
dev <- deviance(m) # residual scaled deviance of the orig. model
dfr <- df.residual(m) # residual degrees of freedom of the orig. model
dev.red <- deviance(m.red) # residual scaled deviance of the reduced model
dfr.red <- df.residual(m.red) # residual degrees of freedom of the reduced model
lrt2 <- dev.red - dev # likelihood ratio statistics (38555.7)
df2 <- dfr.red - dfr # degrees of freedom (3.2)
1-pchisq(lrt2, df2) # p value (0)
# LRT using anova
anova(m, m.red, test="LRT") # p value (0.001)
```