How to extract the formula from a step regression?

r, regression

Solution

You can simply extract it from your `slm1` object using the `formula` method for `lm` object

formula(slm1)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality

Problem

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 ```

Original source

Related problems