"R stepAIC()"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 4개는 보이지 않습니다)
3번째 줄: 3번째 줄:
* "Choose A Model By AIC In A Stepwise Algorithm {{해석|AIC에 따라 단계적 알고리즘으로 모델 선택}}"
* "Choose A Model By AIC In A Stepwise Algorithm {{해석|AIC에 따라 단계적 알고리즘으로 모델 선택}}"


<syntaxhighlight lang='r' run>
<syntaxhighlight lang='r' notebook>
options(echo=T)
library(MASS)
library(MASS)
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)
11번째 줄: 12번째 줄:
     trace = FALSE)
     trace = FALSE)
quine.stp$anova
quine.stp$anova
 
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
cpus1 <- cpus
cpus1 <- cpus
for(v in names(cpus)[2:7])
for(v in names(cpus)[2:7])
21번째 줄: 23번째 줄:
cpus.lm2 <- stepAIC(cpus.lm, trace = FALSE)
cpus.lm2 <- stepAIC(cpus.lm, trace = FALSE)
cpus.lm2$anova
cpus.lm2$anova
 
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
example(birthwt)
example(birthwt)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
birthwt.glm <- glm(low ~ ., family = binomial, data = bwt)
birthwt.glm <- glm(low ~ ., family = binomial, data = bwt)
birthwt.step <- stepAIC(birthwt.glm, trace = FALSE)
birthwt.step <- stepAIC(birthwt.glm, trace = FALSE)
birthwt.step$anova
birthwt.step$anova
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
birthwt.step2 <- stepAIC(birthwt.glm, ~ .^2 + I(scale(age)^2)
birthwt.step2 <- stepAIC(birthwt.glm, ~ .^2 + I(scale(age)^2)
     + I(scale(lwt)^2), trace = FALSE)
     + I(scale(lwt)^2), trace = FALSE)
birthwt.step2$anova
birthwt.step2$anova
 
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
quine.nb <- glm.nb(Days ~ .^4, data = quine)
quine.nb <- glm.nb(Days ~ .^4, data = quine)
quine.nb2 <- stepAIC(quine.nb)
quine.nb2 <- stepAIC(quine.nb)
</syntaxhighlight>
<syntaxhighlight lang='r' notebook>
quine.nb2$anova
quine.nb2$anova
</syntaxhighlight>
</syntaxhighlight>


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[AIC]]
* [[AIC]]
* [[R step()]]
* [[R step()]]
* [[R addterm()]]
* [[R addterm()]]
* [[R dropterm()]]
* [[R dropterm()]]
* [[R 전진선택법]]
* [[R 후진제거법]]
}}


==참고==
==참고==

2021년 4월 27일 (화) 23:46 기준 최신판

1 개요[ | ]

R stepAIC()
  • "Choose A Model By AIC In A Stepwise Algorithm → AIC에 따라 단계적 알고리즘으로 모델 선택"
options(echo=T)
library(MASS)
quine.hi <- aov(log(Days + 2.5) ~ .^4, quine)
quine.nxt <- update(quine.hi, . ~ . - Eth:Sex:Age:Lrn)
quine.stp <- stepAIC(quine.nxt,
    scope = list(upper = ~Eth*Sex*Age*Lrn, lower = ~1),
    trace = FALSE)
quine.stp$anova
cpus1 <- cpus
for(v in names(cpus)[2:7])
  cpus1[[v]] <- cut(cpus[[v]], unique(quantile(cpus[[v]])),
                    include.lowest = TRUE)
cpus0 <- cpus1[, 2:8]  # excludes names, authors' predictions
cpus.samp <- sample(1:209, 100)
cpus.lm <- lm(log10(perf) ~ ., data = cpus1[cpus.samp,2:8])
cpus.lm2 <- stepAIC(cpus.lm, trace = FALSE)
cpus.lm2$anova
example(birthwt)
birthwt.glm <- glm(low ~ ., family = binomial, data = bwt)
birthwt.step <- stepAIC(birthwt.glm, trace = FALSE)
birthwt.step$anova
birthwt.step2 <- stepAIC(birthwt.glm, ~ .^2 + I(scale(age)^2)
    + I(scale(lwt)^2), trace = FALSE)
birthwt.step2$anova
quine.nb <- glm.nb(Days ~ .^4, data = quine)
quine.nb2 <- stepAIC(quine.nb)
quine.nb2$anova

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}