我正在尝试提取AIC值和相应的模型公式并创建表格。
library(Flury)
data(microtus)
mc=microtus
class(mc$Group)
# making 0,1,2 groups
mc$Group=as.numeric(mc$Group)-1
# First, I divide the datatset in a Known (known) and Unknown(uk) groups.
# Unknown Subset Construction
uk=subset(mc,Group==2)
known=subset(mc,Group!=2)
step(glm(Group ~., data = known, family = "binomial"), direction="both")
我想从逐步回归中提取AIC并创建一个这样的表(当然,不是手动进行的):
Models AIC
Group ~ M1Left + M2Left + M3Left + Foramen + Pbone + Length +
Height + Rostrum 32.96
Group ~ M1Left + M3Left + Foramen + Pbone + Length + Height +
Rostrum 30.97
Group ~ M1Left + M3Left + Foramen + Length + Height + Rostrum 29.31
Group ~ M1Left + M3Left + Foramen + Length + Height 27.1
答案 0 :(得分:3)
由step
返回的模型对象具有一个anova
组件(一个数据框架),其中包括每个步骤的AIC。
> model <- step(glm(Group ~., data = known, family = "binomial"), direction="both")
> model$anova
Step Df Deviance Resid. Df Resid. Dev AIC
1 NA NA 80 14.96195 32.96195
2 - M2Left 1 0.003070711 81 14.96502 30.96502
3 - Pbone 1 0.340784942 82 15.30580 29.30580
4 - Rostrum 1 0.396842871 83 15.70264 27.70264