#library packages
library(survival)
library(survminer)
## Loading required package: ggplot2
## Loading required package: ggpubr
##
## Attaching package: 'survminer'
## The following object is masked from 'package:survival':
##
## myeloma
#load data
d1<-survival::gbsg
#kaplan meier(hormones)
surv_obj<-Surv(time=d1$rfstime,event=d1$status)
s1<-survfit(surv_obj~1,,data=d1)
#library(ggsurvfit)
library(ggsurvfit)
fit_hormon<-survfit(surv_obj~hormon,data=gbsg)
ggsurvfit(fit_hormon,linewidth=1)+
labs(x="rfstime",y="status")+
add_confidence_interval()
#kaplan meier(menopause)
fit_meno<-surv_fit(surv_obj~meno,data=gbsg)
ggsurvfit(fit_meno,linewidth=1)+
labs(x="rfstime",y="status")+
add_confidence_interval()
#Nelson allen (hormones)
nahormones<-survfit(Surv(rfstime,status)~hormon,data=gbsg)
plot(nahormones,fun="cumhaz",xlab="rfstime",ylab="cumulative probability",main="NA Estimator",col="red")
#NA estimator(menopause)
namenopause<-survfit(Surv(rfstime,status)~meno,data=gbsg)
plot(namenopause,fun="cumhaz",xlab="rfstime",ylab="cumulative probability",main="NA Estimator",col="blue")
#Log Rank test
logrankres_hormon<-survdiff(Surv(rfstime,status)~hormon,data=gbsg)
logrankres_hormon
## Call:
## survdiff(formula = Surv(rfstime, status) ~ hormon, data = gbsg)
##
## N Observed Expected (O-E)^2/E (O-E)^2/V
## hormon=0 440 205 180 3.37 8.56
## hormon=1 246 94 119 5.12 8.56
##
## Chisq= 8.6 on 1 degrees of freedom, p= 0.003
logrankres_meno<-survdiff(Surv(rfstime,status)~meno,data=gbsg)
logrankres_meno
## Call:
## survdiff(formula = Surv(rfstime, status) ~ meno, data = gbsg)
##
## N Observed Expected (O-E)^2/E (O-E)^2/V
## meno=0 290 119 124 0.164 0.28
## meno=1 396 180 175 0.115 0.28
##
## Chisq= 0.3 on 1 degrees of freedom, p= 0.6
from the above results,hormonal therapy with a p-value of 0.003 is the only significant variable. # Cox proportion Hazard
cox_res<-coxph(Surv(rfstime, status)~hormon+meno,data=gbsg)
cox_res
## Call:
## coxph(formula = Surv(rfstime, status) ~ hormon + meno, data = gbsg)
##
## coef exp(coef) se(coef) z p
## hormon -0.4003 0.6701 0.1282 -3.124 0.00179
## meno 0.1526 1.1649 0.1212 1.259 0.20807
##
## Likelihood ratio test=10.42 on 2 df, p=0.005464
## n= 686, number of events= 299
the above results show that hormonal therapry is the only significant variable.