Search code examples
rregressionvariable-selection

StepAIC() stopping point


I am trying to understand the stopping point of StepAIC(). When using direction = 'backward', does it stop if any further deletion of the terms no longer decreases model AIC? Example as follows:

fm<- lm(mpg ~ ., data = mtcars)
require(MASS)
fit_fm <- stepAIC(fm, direction = 'backward')
#The final step stopped at:
Step:  AIC=61.31
mpg ~ wt + qsec + am

       Df Sum of Sq RSS  AIC
<none>              169 61.3
- am    1      26.2 195 63.9
- qsec  1     109.0 278 75.2
- wt    1     183.3 353 82.8

Does this mean deleting any of the terms wt, qsec, or am will not decrease model AIC at all (i.e., all AICs=61.31)?


Solution

  • Yes, that's right. You can check this yourself (the second value from extractAIC() is the AIC):

    extractAIC(fm_nowt <- update(fit_fm, . ~ . -wt))
    ## [1]  3.00000 82.79016
    extractAIC(fm_noqsec <- update(fit_fm, . ~ . -qsec))
    ## [1]  3.00000 75.21711
    extractAIC(fm_noam <- update(fit_fm, . ~ . -am))
    ## [1]  3.00000 63.90843
    

    Note that the values returned by extractAIC() are different from those returned by AIC() in base R, but the differences between model AICs (which is all we really care about) are the same:

     AIC(fm_nowt)- AIC(fit_fm)
    [1] 21.48286
    > extractAIC(fm_nowt)- extractAIC(fit_fm)
    [1] -1.00000 21.48286