0

I am removing unnecessary/spurious variables from my data using 'step' function. I am using the folloeing code:

  state.x77
  st = as.data.frame(state.x77)
  colnames(st)[4] = "Life.Exp"         # no spaces in variable names, please
  colnames(st)[6] = "HS.Grad"
  model1 = lm(Life.Exp ~ Population + Income + Illiteracy + Murder +
                +                        HS.Grad + Frost + Area, data=st)
  summary(model1)
  modelStep = step(model1, direction="backward")

How do I know the final variables selected by 'step' method?

Edit: I am using the following to find the same. I am looking for any other simpler method.

rownames(summary(modelStep)$coefficients)
user1140126
  • 2,621
  • 7
  • 29
  • 34

1 Answers1

0

All you need is:

st <- as.data.frame(state.x77)
colnames(st)[4] = "Life.Exp"         # no spaces in variable names, please
colnames(st)[6] = "HS.Grad"
model1 = lm(Life.Exp ~ Population + Income + Illiteracy + Murder+HS.Grad + Frost + Area, data=st)
modelStep <- step(model1, direction="backward")$coefficients
modelStep

This will be your output when you type in modelStep:

> modelStep
  (Intercept)    Population        Murder       HS.Grad         Frost 
 7.102713e+01  5.013998e-05 -3.001488e-01  4.658225e-02 -5.943290e-03