Skip to main content
formatted; light editing
Source Link
gung - Reinstate Monica
  • 147.5k
  • 89
  • 406
  • 717

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

[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))$$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

[1] 8775.331

sd(sapply(res.rand, "[[", "aic"))
[1] 1.267697

[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

[1] -0.001984873

mean(sapply(res.rand, "[[", "adj.r2"))

[1] -0.00202206

[1] -0.00202206

sd(sapply(res.rand, "[[", "adj.r2"))
[1] 0.001057333

[1] 0.001057333

Can you findfigure out what I missed?

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 find out what I missed?

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?

Source Link

Adding uncorrelated variables to glm increases AIC

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 find out what I missed?