【发布时间】:2020-11-23 16:04:15
【问题描述】:
我一直在使用 lm 回归函数并使用逐步回归。不幸的是,逐步似乎并没有太大的灵活性。进入/移除标准和重要性无法调整。
使用 mtcars,我运行这些代码
FitAll <- lm(mpg ~ . ,data=mtcars) # Fit reg model with all variables
FitStart <- lm(mpg~1,data=mtcars) # Fit reg model with just intercept
step(FitStart, direction = "both" , scope=formula(FitAll)) # stepwise, "both"=forward&backward
它告诉我模型中有 3 个变量 wt + cyl + hp 的逐步停止。当我使用这些运行回归模型时,我发现一些变量在 5% 时并不显着。
fit <- lm(formula = mpg ~ wt + cyl + hp, data = mtcars)
summary(fit)
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 38.75179 1.78686 21.687 < 2e-16 ***
wt -3.16697 0.74058 -4.276 0.000199 ***
cyl -0.94162 0.55092 -1.709 0.098480 .
hp -0.01804 0.01188 -1.519 0.140015
有没有办法使用这个 lm 和 step 函数来指定进入和退出标准。此外,有时我想将所有变量的严格性提高到 1%。有没有办法用这种方法指定进入/退出标准和重要性级别?有没有更好的包可以使用? 非常感谢任何帮助。谢谢
【问题讨论】:
-
我快速浏览了文档,看起来 step() 使用 Akakie 信息标准 (AIC) 来选择模型,而不是 p 值阈值。
-
@Bill - 感谢您指出它是 AIC。我找到了this thread,它可以解决问题。
标签: r regression lm