4

我正在运行逐步回归,我想提取最终公式以在另一个回归中使用它。

使用这个例子:

lm1 <- lm(Fertility ~ ., data = swiss)
slm1 <- step(lm1)

我希望能够将其分配给公式对象:

Fertility ~ Agriculture + Education + Catholic + 
    Infant.Mortality
4

2 回答 2

9

您可以使用对象的方法简单地从对象中slm1提取它formulalm

formula(slm1)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality
于 2013-07-03T20:30:30.293 回答
4

知道了:

> as.formula(slm1$call)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality
于 2013-07-03T20:15:53.370 回答