0

I'm seeing some "inconsistencies" on how R calculates the Akaike Information Criterion (AIC) for linear regression models. I'd like to get its expression so I can calculate it myself. The issues I'm referring to can be seen here:

complex_model <- lm(mpg~hp+wt, mtcars)
simple_model <- lm(mpg~hp, mtcars)
AIC(complex_model)
AIC(simple_model)
step(complex_model)

The difference in AIC between both models stay the same, however the values don't. I understand that for all practical effect in model selection this doesn't change much, but why is the results different? What expressions are these values obtained from?

David
  • 2,422
  • 1
  • 4
  • 15
  • See the discussion on AIC: https://stats.stackexchange.com/questions/524258/why-does-the-akaike-information-criterion-aic-sometimes-favor-an-overfitted-mo/524311#524311 – Match Maker EE Jun 01 '21 at 21:23

1 Answers1

2

See this answer:

What is the difference between AIC() and extractAIC() in R?

I discovered this by inspecting the code of the step() function, looking at the help for extractAIC() and, finding that confusing, searching CrossValidated.

stweb
  • 196
  • 8