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?