Tag Archives: R

Kaplan-Meier Curves with R

While Excel (and similar spreadsheet programs) are powerful, they are not really suited for survival analysis. For example, graphing Kaplan-Meier curves with Excel is less than ideal. Survival analysis will often require a statistical software package, like  SAS, SPSS, STATA, XLSTAT, etc. R is a free alternative that is widely used by academics. Be warned, the learning curve for R is steep, but the references below should be helpful.

An R script entitled KM graphs.R is provided that will allow you to graph Kaplan-Meier curves using R. You will have to download and install R (and RStudio if you like). Professor Roger Peng, at Johns Hopkins University, has an entire online course introducing R on YouTube and Coursera. This YouTube video shows you how to install R on Windows; he also has a video to install R on a Mac. You will also need to format the survival data you want to graph in a .CSV file. The file should have three columns: time to event, event occurrence, and treatment. The event occurrence and treatment columns should contain either a 0 or 1 to indicate whether the event has occurred or whether an individual received treatment, respectively. An example file entitled data.CSV is provided.

Once you have installed R, download the data.CSV file to the working directory in R and run the KM graphs.R script. You can then replace the data in the .CSV file with the data you want to graph.

References:

  1. UCLA Institute for Digital Research and Education.
  2. Use Software R to do Survival Analysis and Simulation.
  3. Survival Analysis in R (www.openintro.org).
Advertisements
Tagged , , ,