postscript("l02.ps") larynx<-as.data.frame( scan("larynx.dat", what=list(stage=0,time=0,y1=0,y2=0,status=0))) wean<-as.data.frame(scan("bfeed.dat", what=list(time=0,state=0,race=0, poverty=0,smoked=0, alcohol=0,age=0,year=0,edu=0,prenatal=0))) #****************************************************/ #* Kaplan--Meier curve for the combined larynx data */ #****************************************************/ library(survival) sf.larynx<-survfit(Surv(larynx$time,larynx$status), conf.type="none") summary(sf.larynx) print(sf.larynx) plot(sf.larynx,main="Larynx Tumor Survival") plot(survfit(Surv(larynx$time,larynx$status), conf.type="plain"), main="Larynx Tumor Survival", sub="Confidence Interval on Raw Scale") #*******************************************************/ #* Draw confidence intervals for the survival function */ #* of weaning two ways. Do this on a subset whose */ #* mothers smoked and drank. */ #*******************************************************/ alch<-wean[(wean$alcohol==1)&(wean$smoked==1),] sf<-survfit(Surv(time,status),data=larynx,conf.type="plain") summary(sf) print(sf) plot(sf,main='Plot of weaning with confidence limits') # We can skip conf.type argument below, since log is default. plot(survfit(Surv(time,status),data=larynx, conf.type="log"), main="Plot of weaning with log scale confidence limits") #********************************************************/ #* Plot Nelson-Aalen estimator of the cumulative hazard */ #********************************************************/ plot(survfit(coxph(Surv(alch$time,alch$state)~1)), fun="cumhaz")