myData <- read.csv('~/Project/c_storedata2.csv', na.strings = c(""," ",NA),encoding="UTF-8")
library(survival)
library(survminer)
KM = survfit(Surv(event = myData$status,time = myData$op_days) ~ 1, data = myData)
ggsurvplot(KM,
conf.int = TRUE,
risk.table = TRUE,
risk.table.height = 0.4,
ggtheme = theme_bw(),
palette = c("#2E9FDF"),
font.x = c(10),
font.y = c(10),
font.tickslab = c(10),
surv.median.line = "hv",
break.time.by = 2000,
xlim = c(0,20000))
위의 그래프는 서울시 전체 편의점 생존률을 나타낸 그래프이다. 그래프에서 점선으로 표시된 생존율의 50% 구간이 약 2300일로, 약 6년정도가 서울시 전체 편의점 생존율의 50%에 해당하는 생존일이다.
KM2 = survfit(Surv(event = myData$status,time = myData$op_days) ~ myData$name,
data = myData)
SURVPLOT2 = ggsurvplot(KM2,
conf.int = TRUE,
risk.table = TRUE,
risk.table.height = 0.4,
ggtheme = theme_bw(),
font.x = c(10),
font.y = c(10),
font.tickslab = c(10),
break.time.by = 2000,
xlim = c(0,20000),
pval = TRUE,
palette = c("blue", "red", "yellow", "brown", "green",
"pink", "violet"),
legend = c(0.9,0.5),
legend.title = "Brand",
legend.labs = c("훼미리마트", "cu", "gs25", "세븐일레븐",
"미니스톱", "이마트24", "기타"))
SURVPLOT2
위 그래프는 서울시 각 편의점 생존률을 브랜드별로 나타낸 그래프이다. 50% 생존 구간인 약 2000일까지는 기타 편의점의 생존률이 가장 낮지만 일정 시간이 지나면 GS25의 생존률이 가장 낮아진다. 시간이 지남에 따라 이마트24의 생존률이 다른 편의점들에 비해 눈에 띄게 높은 것을 알 수 있다.
KM3 = survfit(Surv(event = myData$status,time = myData$op_days) ~ myData$location,
data = myData)
SURVPLOT3 = ggsurvplot(KM3,
conf.int = TRUE,
risk.table = TRUE,
risk.table.height = 0.4,
ggtheme = theme_bw(),
font.x = c(10),
font.y = c(10),
font.tickslab = c(10),
break.time.by = 2000,
xlim = c(0,20000),
pval = TRUE,
palette = c("blue", "red","brown", "green", "purple"),
legend = c(0.9,0.6),
legend.title = "location",
legend.labs = c("강남","강동","마용성","강북","강서"))
SURVPLOT3
위 그래프는 서울시 각 위치별 편의점 생존률을 나타낸 그래프이다. 초반의 생존률은 다섯구역 모두 비슷한 양상을 보이나 시간이 지남에 따라 강북의 생존률은 낮아지면서 마용성의 생존률이 다른 구역에 비해 높아진다.
survdiff(Surv(event = myData$status,time = myData$op_days) ~ myData$name,
data = myData)
## Call:
## survdiff(formula = Surv(event = myData$status, time = myData$op_days) ~
## myData$name, data = myData)
##
## N Observed Expected (O-E)^2/E (O-E)^2/V
## myData$name=CU 2707 902 1047 19.96 25.71
## myData$name=GS25 3642 1647 1510 12.46 18.05
## myData$name=기타 398 364 209 115.75 121.01
## myData$name=미니스톱 523 424 371 7.52 8.22
## myData$name=세븐일레븐 2601 1121 1451 75.12 108.60
## myData$name=이마트24 598 155 215 16.81 17.65
## myData$name=훼미리마트 412 382 193 186.42 196.09
##
## Chisq= 437 on 6 degrees of freedom, p= <2e-16
여기서 Expected값은 원래 나와야하는 값, Observed 값은 실제로 나온 값이다. Chisq가 437, p값이 0.05보다 작으므로 서울시 각 편의점 브랜드별 생존률의 차이가 유의하다는 것을 알 수 있다.
survdiff(Surv(event = myData$status,time = myData$op_days) ~ myData$location,
data = myData)
## Call:
## survdiff(formula = Surv(event = myData$status, time = myData$op_days) ~
## myData$location, data = myData)
##
## N Observed Expected (O-E)^2/E (O-E)^2/V
## myData$location=강남 2481 1262 1203 2.925 3.870
## myData$location=강동 2313 974 1089 12.229 15.674
## myData$location=강북 1886 875 947 5.539 6.859
## myData$location=강서 3160 1390 1251 15.332 20.581
## myData$location=마용성 1041 494 504 0.197 0.219
##
## Chisq= 36.3 on 4 degrees of freedom, p= 3e-07
위의 검정 결과 Chisq값이 36.3으로 편의점 브랜드별 생존률보다는 낮은 값이지만 p값이 0.05 보다 작으므로 각 위치별 편의점점 생존률의 차이 또한 유의하다고 할 수 있다.
ovarian_cox <- coxph(Surv(myData$op_days, myData$status==1) ~ as.factor(myData$name), data=myData)
summary(ovarian_cox)
## Call:
## coxph(formula = Surv(myData$op_days, myData$status == 1) ~ as.factor(myData$name),
## data = myData)
##
## n= 10881, number of events= 4995
##
## coef exp(coef) se(coef) z Pr(>|z|)
## as.factor(myData$name)GS25 0.23715 1.26763 0.04147 5.719 1.07e-08
## as.factor(myData$name)기타 0.71046 2.03494 0.06233 11.399 < 2e-16
## as.factor(myData$name)미니스톱 0.28800 1.33376 0.05950 4.840 1.30e-06
## as.factor(myData$name)세븐일레븐 -0.10483 0.90048 0.04529 -2.315 0.0206
## as.factor(myData$name)이마트24 -0.17939 0.83578 0.08696 -2.063 0.0391
## as.factor(myData$name)훼미리마트 0.84449 2.32680 0.06171 13.685 < 2e-16
##
## as.factor(myData$name)GS25 ***
## as.factor(myData$name)기타 ***
## as.factor(myData$name)미니스톱 ***
## as.factor(myData$name)세븐일레븐 *
## as.factor(myData$name)이마트24 *
## as.factor(myData$name)훼미리마트 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## as.factor(myData$name)GS25 1.2676 0.7889 1.1687 1.3750
## as.factor(myData$name)기타 2.0349 0.4914 1.8009 2.2993
## as.factor(myData$name)미니스톱 1.3338 0.7498 1.1869 1.4987
## as.factor(myData$name)세븐일레븐 0.9005 1.1105 0.8240 0.9841
## as.factor(myData$name)이마트24 0.8358 1.1965 0.7048 0.9911
## as.factor(myData$name)훼미리마트 2.3268 0.4298 2.0617 2.6259
##
## Concordance= 0.569 (se = 0.005 )
## Likelihood ratio test= 381.5 on 6 df, p=<2e-16
## Wald test = 418.5 on 6 df, p=<2e-16
## Score (logrank) test = 436.7 on 6 df, p=<2e-16
Cu 편의점은 Reference Group으로 이와 비교한 분석 값이 도출된다. Cu에 비해 Gs25, 기타, 미니스톱, 훼미리마트는 위험률이 높고 반대로 세븐일레븐과 이마트24는 기준 그룹에 비해 위험률이 낮다는 것을 알 수 있다.
ovarian_cox2 <- coxph(Surv(myData$op_days, myData$status==1) ~ as.factor(myData$location), data=myData)
summary(ovarian_cox2)
## Call:
## coxph(formula = Surv(myData$op_days, myData$status == 1) ~ as.factor(myData$location),
## data = myData)
##
## n= 10881, number of events= 4995
##
## coef exp(coef) se(coef) z Pr(>|z|)
## as.factor(myData$location)강동 -0.16004 0.85211 0.04273 -3.745 0.00018
## as.factor(myData$location)강북 -0.12794 0.87991 0.04403 -2.906 0.00366
## as.factor(myData$location)강서 0.05731 1.05899 0.03902 1.469 0.14191
## as.factor(myData$location)마용성 -0.06816 0.93411 0.05309 -1.284 0.19918
##
## as.factor(myData$location)강동 ***
## as.factor(myData$location)강북 **
## as.factor(myData$location)강서
## as.factor(myData$location)마용성
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## as.factor(myData$location)강동 0.8521 1.1736 0.7836 0.9265
## as.factor(myData$location)강북 0.8799 1.1365 0.8072 0.9592
## as.factor(myData$location)강서 1.0590 0.9443 0.9810 1.1432
## as.factor(myData$location)마용성 0.9341 1.0705 0.8418 1.0365
##
## Concordance= 0.521 (se = 0.004 )
## Likelihood ratio test= 36.32 on 4 df, p=2e-07
## Wald test = 36.21 on 4 df, p=3e-07
## Score (logrank) test = 36.3 on 4 df, p=3e-07
강남이 Reference Group으로 강남 구역에 비해 강동, 강북, 마용성 구역은 위험률이 낮지만 강서 구역은 강남에 비해 위험률이 높은 것을 확인할 수 있다. 하지만 강동과 강북 구역의 값은 유의하지만 강서와 마용성의 값은 통계적으로 유의하지 않으므로 위험률의 차이에 의미가 없다.
ovarian_cox3 <- coxph(Surv(myData$op_days, myData$status==1) ~ as.factor(myData$name) + myData$location, data=myData)
summary(ovarian_cox3)
## Call:
## coxph(formula = Surv(myData$op_days, myData$status == 1) ~ as.factor(myData$name) +
## myData$location, data = myData)
##
## n= 10881, number of events= 4995
##
## coef exp(coef) se(coef) z Pr(>|z|)
## as.factor(myData$name)GS25 0.23881 1.26973 0.04153 5.751 8.88e-09
## as.factor(myData$name)기타 0.70950 2.03297 0.06271 11.315 < 2e-16
## as.factor(myData$name)미니스톱 0.27420 1.31548 0.05986 4.581 4.63e-06
## as.factor(myData$name)세븐일레븐 -0.10339 0.90178 0.04542 -2.276 0.02284
## as.factor(myData$name)이마트24 -0.17407 0.84024 0.08706 -1.999 0.04556
## as.factor(myData$name)훼미리마트 0.84102 2.31873 0.06201 13.564 < 2e-16
## myData$location강동 -0.10008 0.90477 0.04314 -2.320 0.02034
## myData$location강북 -0.07607 0.92675 0.04424 -1.719 0.08554
## myData$location강서 0.10433 1.10996 0.03925 2.658 0.00786
## myData$location마용성 -0.02833 0.97206 0.05318 -0.533 0.59414
##
## as.factor(myData$name)GS25 ***
## as.factor(myData$name)기타 ***
## as.factor(myData$name)미니스톱 ***
## as.factor(myData$name)세븐일레븐 *
## as.factor(myData$name)이마트24 *
## as.factor(myData$name)훼미리마트 ***
## myData$location강동 *
## myData$location강북 .
## myData$location강서 **
## myData$location마용성
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## exp(coef) exp(-coef) lower .95 upper .95
## as.factor(myData$name)GS25 1.2697 0.7876 1.1705 1.3774
## as.factor(myData$name)기타 2.0330 0.4919 1.7979 2.2988
## as.factor(myData$name)미니스톱 1.3155 0.7602 1.1699 1.4792
## as.factor(myData$name)세븐일레븐 0.9018 1.1089 0.8250 0.9857
## as.factor(myData$name)이마트24 0.8402 1.1901 0.7084 0.9966
## as.factor(myData$name)훼미리마트 2.3187 0.4313 2.0534 2.6184
## myData$location강동 0.9048 1.1053 0.8314 0.9846
## myData$location강북 0.9268 1.0790 0.8498 1.0107
## myData$location강서 1.1100 0.9009 1.0278 1.1987
## myData$location마용성 0.9721 1.0287 0.8759 1.0788
##
## Concordance= 0.578 (se = 0.005 )
## Likelihood ratio test= 411.2 on 10 df, p=<2e-16
## Wald test = 447.9 on 10 df, p=<2e-16
## Score (logrank) test = 466.3 on 10 df, p=<2e-16
위 분석은 위치와 브랜드 변수를 함께 넣어 회귀분석을 실행한 결과이다. 편의점 브랜드별 위험률의 값에 미미한 차이는 있었으나 크게 달라진 값은 없었으며 유의성 또한 여전히 유의했다. 위치 변수의 위험률도 값에는 조금의 차이가 있었으나 마이너스와 플러스 값의 차이는 없었다. 하지만 강동 구역 값의 유의성이 낮아지면서 강북의 값은 유의하지 않으며 오히려 강서의 값이 유의해진 결과를 볼 수 있다.