step function matching AIC of full model

817 views Asked by At

Shouldn't the

AIC(full) = 275.93

match the output of of the AIC when the step() function runs with the full model which is -9.86 below

Start:  AIC=-9.86
y ~ x + x2

       Df Sum of Sq    RSS      AIC
- x2    1   0.03672 85.372 -11.8147
- x     1   1.03869 86.374 -10.6479
<none>              85.336  -9.8578

Step:  AIC=-11.81
y ~ x

       Df Sum of Sq    RSS     AIC
- x     1     1.004 86.376 -12.646
<none>              85.372 -11.815

Step:  AIC=-12.65
y ~ 1


Call:
lm(formula = y ~ 1, data = data)

Coefficients:
(Intercept)  
   -0.03719  

here is the full code:

set.seed(101)
y = rnorm(100)
x = rnorm(100)
x2 = rnorm(100)
data = data.frame(y = y, x = x, x2 = x2)
null = lm(y~1, data = data)
full = lm(y~x+x2, data = data)
#step(null, scope= list(lower = null, upper = full) , direction="backward", trace = TRUE)
step(full, direction="backward", trace = TRUE)
AIC(full)
1

There are 1 answers

0
Prem On BEST ANSWER

You would need extractAIC instead of AIC

extractAIC(lm(y~x+x2, data = data), scale=0)
#OR
#extractAIC(full, scale=0)

If you refer the documentation ?AIC & ?extractAIC it clearly says that

The log-likelihood and hence the AIC/BIC is only defined up to an additive constant. Different constants have conventionally been used for different purposes and so extractAIC and AIC may give different values (and do for models of class "lm": see the help for extractAIC).


Hope this helps!