# This output file is 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) [1] 10 13+ 18+ 19 23+ 30 36 38+ 54+ 56+ 59 75 93 97 104+ [16] 107 107+ 107+ # 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) Call: survfit(formula = Surv(times, events) ~ 1) time n.risk n.event survival std.err lower 95% CI upper 95% CI 10 18 1 0.944 0.0540 0.844 1.000 19 15 1 0.881 0.0790 0.739 1.000 30 13 1 0.814 0.0978 0.643 1.000 36 12 1 0.746 0.1107 0.558 0.998 59 8 1 0.653 0.1303 0.441 0.965 75 7 1 0.559 0.1412 0.341 0.917 93 6 1 0.466 0.1452 0.253 0.858 97 5 1 0.373 0.1430 0.176 0.791 107 3 1 0.249 0.1392 0.083 0.745