首页 > 解决方案 > R - 使用 stepAIC() 函数时提取最终模型中的变量列表

问题描述

我想在使用该 stepAIC()函数时提取最终模型中的变量名称列表。

我试过了:

attr(terms(backward.aic), "predvars")

但这并没有给我一个清单。

标签: r

解决方案


上市怎么样term.labels

list(attr(terms(quine.stp), "term.labels"))
# [[1]]
#  [1] "Eth"         "Sex"         "Age"         "Lrn"         "Eth:Sex"    
#  [6] "Eth:Age"     "Eth:Lrn"     "Sex:Age"     "Sex:Lrn"     "Age:Lrn"    
# [11] "Eth:Sex:Lrn" "Eth:Age:Lrn"

数据

library(MASS)
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)
quine.nxt <- update(quine.hi, . ~ . - Eth:Sex:Age:Lrn)
quine.stp <- stepAIC(quine.nxt,
                     scope = list(upper = ~Eth*Sex*Age*Lrn, lower = ~1),
                     trace = FALSE)

推荐阅读