0

我正在使用“步骤”功能从我的数据中删除不必要的/虚假变量。我正在使用以下代码:

  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")

我如何知道“步骤”方法选择的最终变量?

编辑:我正在使用以下内容来查找相同的内容。我正在寻找任何其他更简单的方法。

rownames(summary(modelStep)$coefficients)
4

1 回答 1

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 
于 2014-07-13T17:46:59.047 回答