【发布时间】:2022-11-19 21:05:51
【问题描述】:
假设我有一个包含多个变量的表,a - h,其中 h 是目标/y/预测变量:
a <- rnorm(10,5,1)
b <- rnorm(10,5,1)
c <- rnorm(10,5,1)
d <- rnorm(10,5,1)
e <- rnorm(10,5,1)
f <- rnorm(10,5,1)
g <- rnorm(10,5,1)
h <- rnorm(10,5,1)
df = data.frame(a,b,c,d,e,f,g,h)
我想运行 AIC 以确定预测 h 的最佳模型。为此,我需要运行df[1:7] 的每一个组合。所以我需要以下 AIC:
lm(fomula= h ~ a+b+c+d+e+f+g)
lm(fomula= h ~ a+b+c+d+e+f)
lm(fomula= h ~ a+b+c+d+e)
以及变量的所有其他配置。有什么办法可以做到这一点吗?
要获得我尝试过的变量的所有可能公式:
library(combinat)
combn(colnames(df[,1:7]))
但是,我只得到:
[1] "a" "b" "c" "d" "e" "f" "g"
作为上面代码的输出,这与我最终想要的相去甚远。
【问题讨论】:
-
从 MASS 包中查看
stepAIC -
更好的是,使用
leaps包在没有逐步约束的情况下获得最佳子集回归。 (或glmulti或bestglm)
标签: r combinations permutation