Introduction to Survival Analysis - erynmcfarlane/StatsGenLabProtocols GitHub Wiki

Intro Survival Analysis.pdf

link to the primer for survival analyses (includes R tutorials!): https://doi.org/10.1002/ecs2.3238

a very brief tutorial (from the slides) demonstrating the structure of the data frame used to plot a survival curve in R using the package "survival"

library(survival)

mock dataframe where t = time to event and status indicates whether or not the data is censored, 1 = not censored and 0 = censored

t <- c(10, 7, 32, 23, 22, 6, 16, 34, 32, 25, 
       11, 20, 19, 6, 17, 35, 6, 13, 9, 6, 10)

status <- c(1, 1, 0, 1, 1, 1, 1, 0, 0, 0,
           0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0)

the survfit function is used to plot the survival curve using the Kaplan-Meier estimator as the default

plot <- survfit(Surv(t, status) ~ 1)

covariates can be controlled for by entering them after the ~