简体   繁体   English

如何从R中的stepAIC提取重要变量到Excel工作表?

[英]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. 现在,$ anova仅在控制台上列出最终型号。

How do I retrieve the variable names of final model to an excel sheet? 如何将最终模型的变量名称检索到Excel工作表?

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. 您如何将其写入Excel工作表,因为它不是数据框。

Try model.matrix(step) . 试试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. 这将为您提供所选变量的data.frame,您可以将其写入任何文本文件并导入到excel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM