Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract the formula from a step regression?

Tags:

r

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
like image 334
Pierre Lapointe Avatar asked Dec 11 '22 13:12

Pierre Lapointe


1 Answers

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

formula(slm1)
Fertility ~ Agriculture + Education + Catholic + Infant.Mortality
like image 193
dickoa Avatar answered Jan 05 '23 00:01

dickoa