본문 바로가기

깜신의 통계 이야기

2018년5월2일 9차 통계워크샵 강의록

안녕하세요.

깜신 김종엽입니다.


8차 워크샵 이후, 시간이 꽤 흘렀는데요.

그래도 잊지 않고 기다려주신 교수님들께 보답하고자

9차 워크샵을 진행하게 되었습니다.


아래 코드는 내일 워크샵에서 진행할 내용입니다.

참고하시고요, 멋진 수업이 될 수 있도록 노력하겠습니다.


감사합니다.



########## Logistic Regression ########

require(survival)

str(colon)

colon1 <- na.omit(colon)

View(colon)

View(colon1)

result <- glm(status ~ rx+sex+age+obstruct+perfor + adhere + nodes + differ + extent + surg, family = binomial, data=colon1)

summary(result)


reduced.model = step(result)

summary(reduced.model)

require(moonBook)

extractOR(reduced.model)

fit = glm(formula = status ~ rx + obstruct + adhere + nodes + extent + surg, family = binomial, data = colon1)

fit.od = glm(formula = status ~ rx + obstruct + adhere + nodes + extent + surg, family = quasibinomial, data = colon1) 

pchisq(summary(fit.od)$dispersion*fit$df.residual, fit$df.residual, lower = F)

#0.2803691이 값이 0.05보다 크다면 과산포는 없다고 확신할 수 있습니다.


?ORplot()

plot()

ORplot(fit, main = "Plot for Odds Ratios")

ORplot(fit, type=2, show.OR=FALSE, show.CI=TRUE, pch=15, lwd=2, col=c("darkblue", "red"), main="Plot of OR" )

ORplot(fit, type=3, show.OR=FALSE, show.CI=TRUE, pch=15, lwd=2, col=c("darkblue", "red"), main="Plot of OR")


##### Poisson Regression #######

install.packages("robust")

library(robust)

data(breslow.dat, package = "robust")

summary(breslow.dat)


install.packages("qcc")

library(qcc)

qcc.overdispersion.test(breslow.dat$sumY, type="poisson")


fit = glm(sumY ~ Base + Age + Trt, family = quasipoisson, data= breslow.dat)

summary(fit)


install.packages("moonBook")

library(moonBook)

extractOR(fit)

extractOR(fit, digits = 3)

ORplot(fit, type = 2, show.CI=TRUE, main="Plot for Quasipoisson")