library(survival) cancer.dat <- read.table("cancer.dat", col.names=c("Age","Smear","Infil","Index","Blasts","Temp","Resp","Time","Status")) time<-cancer.dat[,"Time"] status<-1-cancer.dat[,"Status"] attach(cancer.dat) cancer.cox<-coxph(Surv(time,status)~Age+Smear+Infil+Index+Blasts) summary(cancer.cox) cancer.cox1<-coxph(Surv(time,status)~Age) cancer.cox1 cancer.cox1.mart<-residuals(cancer.cox1,type="martingale") plot(Age,cancer.cox1.mart,ylab="Martingale residual") abline(h=0) lines(lowess(Age,cancer.cox1.mart)) cancer.cox1.dev<-residuals(cancer.cox1,type="deviance") plot(Age,cancer.cox1.dev,ylab="Deviance residual") abline(h=0) lines(lowess(Age,cancer.cox1.dev)) identify(Age,cancer.cox1.dev,n=1) cancer.cox1.shoen<-residuals(cancer.cox1,type="schoenfeld") plot(Age[status==1],cancer.cox1.shoen,xlab="Survival time",ylab="Schoenfeld residual") abline(h=0) lines(lowess(Age[status==1],cancer.cox1.shoen)) agroup<-cancer.dat[,"Age"]-45 agroup[agroup>=0]<-1 agroup[agroup<0]<-0 plot(survfit(Surv(time,status)~agroup),xlab="Survival Time in months",ylab="Proportion surviving",lty=1:2) legend("topright",c("Under 45","45 and over"),lty=1:2) survdiff(Surv(time,status)~agroup)