在 R 中使用 stepAIC 或类似函数,估计最适合的 lm 输出并估计以获得摘要

Using stepAIC or comparable function in R, estimating best-fit lm output and estimating to get summary

来自新 R 用户的简单问题 - 我正在尝试在多个不同的回归模型中使用 stepAIC,并且我想了解如何save/estimate 基于输出的回归以获得最佳拟合 "Call" 来自 stepAIC。有没有办法做到这一点?谢谢,非常感谢任何帮助。

从 stepAIC 返回的值有 classes "aov" 和 "lm",因此它会响应 lm 的普通结果会响应的所有函数到.

library(MASS)   # running first example on the help page:
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)

所以这是它的 class 值,然后它 print-ed 出现在控制台上,尽管显然不是它的所有组件。您可以使用 names 找到它们并通过 summary:

获得更多信息
> class(quine.stp)
[1] "aov" "lm" 
> quine.stp
Call:
   aov(formula = log(Days + 2.5) ~ Eth + Sex + Age + Lrn + Eth:Sex + 
    Eth:Age + Eth:Lrn + Sex:Age + Sex:Lrn + Age:Lrn + Eth:Sex:Lrn + 
    Eth:Age:Lrn, data = quine)

Terms:
                     Eth      Sex      Age      Lrn  Eth:Sex  Eth:Age  Eth:Lrn
Sum of Squares  10.68203  0.62388  3.76424  0.65290  0.01533  5.98964  0.01246
Deg. of Freedom        1        1        3        1        1        3        1
                 Sex:Age  Sex:Lrn  Age:Lrn Eth:Sex:Lrn Eth:Age:Lrn Residuals
Sum of Squares   8.68925  0.57977  2.38640     4.69558     2.09602  66.59962
Deg. of Freedom        3        1        2           1           2       125

Residual standard error: 0.7299294
2 out of 23 effects not estimable
Estimated effects may be unbalanced

感谢您的上述回复,信息量很大!我还找到了一个快速简单的解决方案,即使用 lm.beta 库,它存储具有低 p 值的系数。