library(survival) #Surv() #create survival object #survfit() # nonparametric estimates Kaplan-Meier, Fleming-Harington # estimate baseline hazard for coxph() object #plot() # method for survfit objects - survival curves and related objects #coxph() # Cox model on survival times #survreg() # parametric survival models ##################################################################################### data(lung) head(lung) help(lung) lung$st<-Surv(lung$time,lung$status) lung$st[1:7] sort(lung$st)[1:10] #sorted times km<-survfit(st~1,data=lung) #K-M object km summary(km) ##################################################################################### ###plots plot(km) #simple K-M plot plot(km, fun="event", ylim=c(0,1),ylab="Cumulative risk") plot(km, fun="cumhaz",xlab="Time",ylab="Cumulative hazadr") plot(survfit(st~sex,data=lung),main="Survival in males (blue) and females (red)", xlab="Time since diagnosis (days)", ylab="Survival proportion", cex.axis=1.5, cex.lab=1.5, col=c("blue","red")) ####################################################################################### ###Cox model mas<-coxph(st~age+sex, data=lung) summary(mas) #prediction from Cox model: pred<-survfit(mod, newdata=....) mod is fitted coxph model, newdata specifies the covariate values #proportionality of hazards # cloglog = complementary log-log transform of S(t), estimated log-cumulative hazadrs should be suffucuently parallel plot (survfit(st~sex, data=lung),fun="cloglog",col=1:2,xlim=c(10,2000),xlab="Time(days)", main="Cum.hazard in men (blue) and women(red)") # !violation against the proporcionality m1<-coxph(st~sex+ph.ecog+pat.karno, data=lung) m1 cox.zph(m1) # testing assumption of proporcionality by chcking, wheather the corresponding parameters (& hazard ratios) may vary in time # startified model # if the covariate is not an exposure of interest , but needs to be adjusted -> fit stratified model m2<-coxph(st~strata(sex)+ph.ecog+pat.karno, data=lung) m2 # if the covariate is a factor of interest, one may consider transformations of it - or completely different model - NON-PROPORTIONAL!