Just a quick demo on creating Kaplan Meier estimation using R. Started working with one tutorial that didn’t work but then found something else. More complex example, so here is the basic code you will need.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# Grab some data hmohiv <-read.table("http://www.ats.ucla.edu/stat/r/examples/asa/hmohiv.csv", sep=",", header = TRUE) # make it so the column names can be used as variables attach(hmohiv) # Load the required library library(survival) # Create an object based on survfit, using the formula from Surv hmohiv.surv <- survfit( Surv(time, censor)~ 1, conf.type="none") # Display a table with results summary(hmohiv.surv) # Plot it out plot(hmohiv.surv, xlab="Time", ylab="Survival Probability") # clear the variables detach(hmohiv) |

The output is a Kaplan Meier survival curve.