# Code for the Kaplan-meier chapter # next line may not be necessary if you installed it sometime earlier install.packages("survival", dependencies=TRUE) library(survival) Now load the dataset into R with the following command: mydataframe <- read.delim("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/survival_collett_p290.dat", header=TRUE) names(mydataframe) mydataframe Now create the regression model: library(survival) attach(mydataframe) # now create a survival object/dataset note the upper case S mysurv <- Surv(time, cens) # now create a survival curve object note the lower case S myKMest <- survfit(mysurv~treat, conf.int=FALSE ) plot(myKMest, lty=c(1,3), col=c("blue","red")) title(main= "survival ovarian cancer n=26", xlab="Time (days )", ylab=" % surviving, S(t)") legend(x=10,y=0.2, legend=c("monotherapy","combined"),col=c("blue","red"),lty=c(1,1)) summary(myKMest) # from http://biostat.mc.vanderbilt.edu/wiki/Main/TatsukiRcode # http://biostat.mc.vanderbilt.edu/wiki/pub/Main/TatsukiRcode/TatsukiRcodeKMplot.r # local copy available at: #http://www.robin-beaumont.co.uk/virtualclassroom/book2data/r_code/TatsukiRcodeKMplot.r", # You can use the source command to read a bit of R code from somewhere else # source(file) #################### source("http://www.robin-beaumont.co.uk/virtualclassroom/book2data/r_code/TatsukiRcodeKMplot.r") kmplot(myKMest, mark='|', simple=FALSE, xaxis.at=c(0,200, 400, 600, 800, 1000, 1200), xaxis.lab=c(0,200, 400, 600, 800, 1000, 1200), # n.risk.at lty.surv=c(1,2), lwd.surv=1, col.surv=c(1,4), # survival.curves col.ci=0, # confidence intervals not plotted group.names=c('monotherapy','combined'), group.order=c(1,2), # order of appearance in the n.risk.at table and legend. extra.left.margin=6, label.n.at.risk=TRUE, draw.lines=TRUE, cex.axis=.8, xlab='days', ylab='Survival Probability', # labels grid=TRUE, lty.grid=1, lwd.grid=1, col.grid=grey(.9), legend=TRUE, loc.legend='bottomleft', cex.lab=.8, xaxs='r', bty='L', las=1, tcl=-.2 , # other parameters passed to plot() ) title(main='Chemotherapy for Ovarian cancer', adj=.1, font.main=1, line=0.5, cex.main=1) # let kma = myKmest kmplot(myKMest, mark='', simple=FALSE, xaxis.at=c(0,.5,1:9)*365, xaxis.lab=c(0,.5,1:9), # n.risk.at lty.surv=c(1,2), lwd.surv=1, col.surv=c(1,1,2,2,4,4), # survival.curves col.ci=0, # confidence intervals not plotted group.names=c('Obs ','Obs tumor adh','Lev','Lev tumor adh','Lev+5FU ','Lev+5FU tumor adh'), group.order=c(5,3,1,6,4,2), # order of appearance in the n.risk.at table and legend. extra.left.margin=6, label.n.at.risk=FALSE, draw.lines=TRUE, cex.axis=.8, xlab='Years', ylab='Survival Probability', # labels grid=TRUE, lty.grid=1, lwd.grid=1, col.grid=grey(.9), legend=TRUE, loc.legend='bottomleft', cex.lab=.8, xaxs='r', bty='L', las=1, tcl=-.2 # other parameters passed to plot() ) title(main='Chemotherapy for stage B/C colon cancer', adj=.1, font.main=1, line=0.5, cex.main=1)