Manju Savanth
Manju Savanth

Reputation: 139

How to extract the important variables from stepAIC in R to an excel sheet?

lmModel <- lm(y~.,data.frame(y=y, x=x))
step <- stepAIC(lmModel, direction="both")
step$anova

Stepwise Model Path Analysis of Deviance Table

Initial Model:

y ~ x.Market.Price + x.Quantity + x.Country + x.Incoterm + x.Channel +
x.PaymentTerm

Final Model:

y ~ x.Quantity + x.Country + x.Incoterm + x.PaymentTerm

Question:

Now, $anova list the final model only on the console.

How do I retrieve the variable names of final model to an excel sheet?

For example

as.formula(step)

gives me the final variable data. How do you write this to an excel sheet as it is not a dataframe.

Upvotes: 1

Views: 1520

Answers (1)

TheRimalaya
TheRimalaya

Reputation: 4592

Try model.matrix(step). This will give you a data.frame of the selected variable which you can write to any text file and import to excel.

Upvotes: 1

Related Questions