user1179919
user1179919

Reputation: 11

with BIC for all subset models how to calculate AIC

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)

Now my Subset1 data frame has columns that i wanted except AIC How to get AIC with the BIC i have for all Subset Models

Upvotes: 1

Views: 1328

Answers (1)

David Robinson
David Robinson

Reputation: 78600

As described here, you can get it relative to the BIC:

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

Upvotes: 1

Related Questions