[英]How to extract the formula from a step regression?
I'm running a step regression and I'd like to extract the final formula to use it in another regression. 我正在进行逐步回归,我想提取最终公式,以便在另一个回归中使用它。
Using this example: 使用此示例:
lm1 <- lm(Fertility ~ ., data = swiss)
slm1 <- step(lm1)
I would expect to be able to assign this to a formula object: 我希望能够将其分配给公式对象:
Fertility ~ Agriculture + Education + Catholic +
Infant.Mortality
You can simply extract it from your slm1
object using the formula
method for lm
object 您可以使用
lm
对象的formula
方法从slm1
对象中简单地提取它
formula(slm1)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality
Got it: 得到它了:
> as.formula(slm1$call)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.