# R-commands for Kaplan-Meier estimates # ===================================== # For illustration we will use the melanoma data for patients # with ulceration (treating deaths from other causes as censorings). # We first read the data: melanoma=read.table("http://www.uio.no/studier/emner/matnat/math/STK4080/h12/melanoma.txt",header=T) # We use the survival library, so this has to be loaded. # We compute and plot the Kaplan-Meier estimate with the # standard confidence intervals (3.29): fit.u=survfit(Surv(lifetime,status==1)~1,data=melanoma, subset=(ulcer==1), conf.type="plain") plot(fit.u,mark.time=F,xlim=c(0,10),ylim=c(0,1), xlab="Years since operation") # The summary command lists the Kaplan-Meier estimates with # standard errors (Greenwood) and confidence intervals: summary(fit.u) # The options type="fl" and type="fh2" to the survfit command # give the survival estimate as exp(-Nelson-Aalen). # The options differ in the way they handle tied failure times # [type "fl" uses (3.13) in the ABG-book, while type "fh2" uses (3.12)]. # To get the log-log transformed confidence intervals (3.30) # we use the survfit command with option conf.type="log-log" # The print command gives a crude summary including an estimate # of the median survival time with confidence intervals print(fit.u) The option rmean=10 to the print command gives an estimate of # the restricted mean for the interval [0,10] with standard error.