# Interpreting the step output in R

In R, the step command is supposedly intended to help you select the input variables to your model, right?

The following comes from example(step)#-> swiss & step(lm1)

> step(lm1)
Start:  AIC=190.69
Fertility ~ Agriculture + Examination + Education + Catholic +
Infant.Mortality

Df Sum of Sq    RSS    AIC
- Examination       1     53.03 2158.1 189.86
<none>                          2105.0 190.69
- Agriculture       1    307.72 2412.8 195.10
- Infant.Mortality  1    408.75 2513.8 197.03
- Catholic          1    447.71 2552.8 197.75
- Education         1   1162.56 3267.6 209.36

Step:  AIC=189.86
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality

Df Sum of Sq    RSS    AIC
<none>                          2158.1 189.86
- Agriculture       1    264.18 2422.2 193.29
- Infant.Mortality  1    409.81 2567.9 196.03
- Catholic          1    956.57 3114.6 205.10
- Education         1   2249.97 4408.0 221.43

Call:
lm(formula = Fertility ~ Agriculture + Education + Catholic +     Infant.Mortality, data = swiss)

Coefficients:
(Intercept)       Agriculture         Education
62.1013           -0.1546           -0.9803
Catholic  Infant.Mortality
0.1247            1.0784


Now, when I look at this, I guess the last Step table is the model which we should use? The last few lines include the "Call" function, which describes the actual model and what input variables it includes, and the "Coefficients" are the actual parameter estimates for these values, right? So this is the model I want, right? I'm trying to extrapolate this to my project, where there are more variables.

The last step table is indeed the end result of the "stepwise regression". The caveat here is that usually you don't want to use this approach when there is a principled way to approach your model specification. The call is the lm call which would produce the equation used in the final step. Coefficients are the actual parameter estimates. It is notable that because you did not define a scope or direction parameter step defaulted to a 'backwards' step approach, in which variable terms are evaluated for dropping at each step, at each step if dropping the selected variable decreases the AIC it is removed from the model and the entire process repeats until it becomes the case that no single variable can be dropped. In your example at the final step Fertility ~ Agriculture + Education + Catholic + Infant.Mortality produced an AIC of 189.86, and dropping any one of those variables did not result in a lower AIC (indicative of a better model fit).

The part of the printout at the end is the model you are left with. You can also get it if you capture the value of the step function:

final.mod <- step(lm1)
final.mod