# This R source file is available at www.richardsconsulting.co.uk/lectures # Load in the library of survival functions library(survival) # Create a vector of observation times times<-c(10, 13, 18, 19, 23, 30, 36, 38, 54, 56, 59, 75, 93, 97, 104, 107, 107, 107) # Create a vector of event types -- '1' for death, '0' for censored events<-c(1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0) #Take a look at the survival data -- '+' marks censored observation Surv(times, events) # Calculate the Kaplan-Meier survival estimates kapmei<-survfit(Surv(times, events) ~ 1) # Take a look at the estimates and confidence intervals # Compare these results with the table on page 7 of the red book summary(kapmei) # Plot survival estimates plot(kapmei, xlab="Time", ylab="Proportion surviving", main="Kaplan-Meier estimate of survival function", sub="Dash lines are confidence intervals, tickmarks are censored observations")