I am trying to understand how AIC works. I am using data from this tutorial: https://www.jaredknowles.com/journal/2013/11/25/getting-started-with-mixed-effect-models-in-r
library(lme4) # load library
library(arm) # convenience functions for regression in R
lmm.data <- read.table("http://bayes.acs.unt.edu:8083/BayesContent/class/Jon/R_SC/Module9/lmm.data.txt",
header=TRUE, sep=",", na.strings="NA", dec=".", strip.white=TRUE)
When fitting the first model we get this AIC:
MLexamp <- glm(extro ~ open + agree + social, data=lmm.data)
AIC(MLexamp)
[1] 8774.291
From my understanding, if I add a variable which is totally uncorrelated to the model, the AIC should compensate the overfitting to stay the same in mean, but it appears to correct more than that:
res.rand <- replicate(1000, {
lmm.data$rand.cont <- rnorm(nrow(lmm.data))
list(aic = AIC(glm(extro ~ open + agree + social + rand.cont, data=lmm.data )),
adj.r2 = summary(lm(extro ~ open + agree + social + rand.cont,
data=lmm.data))$adj.r.squared)
}, simplify=F)
mean(sapply(res.rand, "[[", "aic"))
[1] 8775.331
sd(sapply(res.rand, "[[", "aic"))
[1] 1.267697
The AIC is in mean 1 point higher than in the first model.
If I estimate adjusted R squared from lm
, adding the uncorrelated variable has approximately no effect in mean:
OLSexamp <- lm(extro ~ open + agree + social, data = lmm.data)
summary(OLSexamp)$adj.r.squared
[1] -0.001984873
mean(sapply(res.rand, "[[", "adj.r2"))
[1] -0.00202206
sd(sapply(res.rand, "[[", "adj.r2"))
[1] 0.001057333
Can you figure out what I missed?