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)
You would need
extractAIC
instead ofAIC
If you refer the documentation
?AIC
&?extractAIC
it clearly says thatHope this helps!