与所有子集模型的BIC如何计算AIC

时间:2013-07-12 04:34:11

标签: r

library(leaps)

demand.lm = lm(y ~ X, data = Data) 
X = model.matrix(demand.lm)[, -1]
demand.leaps1 = summary(regsubsets(X, Data$Y,data=Data, nbest = 3))
Subsets <- demand.leaps1$which
RSS <- demand.leaps1$rss
adjr2 <- demand.leaps1$adjr2
cp <- demand.leaps1$cp
bic <- demand.leaps1$bic
Subsets1 <- cbind(as.data.frame(Subsets), RSS=RSS,adjR2=adjr2,cp=cp,BIC=bic)

现在我的Subset1数据框包含我想要的列,除了AIC 如何使用BIC获得所有子集模型的AIC

1 个答案:

答案 0 :(得分:0)

正如here所述,您可以相对于BIC获取它:

n <- length(Data$Y)
p <- apply(demand.leaps1$which, 1, sum)
aic <- demand.leaps1$bic - log(n) * p + 2 * p