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

The R documentation for either does not shed much light. All that I can get from this link is that using either one should be fine. What I do not get is why they are not equal.

Fact: The stepwise regression function in R, step() uses extractAIC().

Interestingly, running a lm() model and a glm() 'null' model (only the intercept) on the 'mtcars' data set of R gives different results for AIC and extractAIC().

> null.glm = glm(mtcars$mpg~1) > null.lm = lm(mtcars$mpg~1)

> AIC(null.glm)
[1] 208.7555
> AIC(null.lm)
[1] 208.7555
> extractAIC(null.glm)
[1]   1.0000 208.7555
> extractAIC(null.lm)
[1]   1.0000 115.9434


It is weird, given that both the models above are the same, and AIC() gives the same results for both.

Can anyone throw some light on the issue?

According, to the help for these two function (use ?AIC and ?extractAIC) this is expected.

Note that the AIC is just defined up to an additive constant, because this is also the case for the log-likelihood. This means you should check whether

extractAIC(full.modell) - extractAIC(null.modell)


and

AIC(full.modell) - AIC(null.modell)


give the same result. As long as they do, both functions are equivalent for all practical purposes.

• I'm probably missing something, but I still don't understand why extractAIC(null.lm) != AIC(null.lm) while extractAIC(null.glm) == AIC(null.glm) even though null.lm is the same model as null.glm. Could you expand your answer a little? – smillig Nov 16 '12 at 18:26
• @smillig extractAIC uses different methods for lm fits and glm fits, i.e., extractAIC.lm and extractAIC.glm. You can use getAnywhere to study their code. AIC uses the same method for both. – Roland Nov 17 '12 at 15:18
• I have several pairs of models (with multiple predictors) for which both functions give different results. Model 1: y = x1 + x2, Model 2: y = z + x1 + x2*z. extractAIC() gives lower (negative) value for Model 1, while AIC gives lower (positive) value for Model 2. – Maxim.K Sep 10 '13 at 11:25
• @Maxim.K You give little information on the type of variables and models used. If you did and there are some differences to this question it might be worthwhile to post this as a new question. Hard to say, without knowing the details. – Erik Sep 10 '13 at 12:47
• @Erik I doubt it will be worth much if I say that z is continuous and x2 is categorical (dummified). One would need the data to reproduce and I cannot publish them I'm afraid. – Maxim.K Sep 11 '13 at 11:56