Skip to content

Instantly share code, notes, and snippets.

@daynebatten
Last active August 29, 2015 14:15
Show Gist options
  • Save daynebatten/00e190f3e1b7aef4b49a to your computer and use it in GitHub Desktop.
Save daynebatten/00e190f3e1b7aef4b49a to your computer and use it in GitHub Desktop.
# Use the survival library
library(survival)
# Read in the NetLixx data... yes, I use Windows.
net_lixx <- read.csv('C:/Users/dayne/Desktop/NetLixx.csv')
# Create a "survival object" for each observation, using time and churn data.
net_lixx$survival <- Surv(net_lixx$time, net_lixx$churned == 1)
# Fit a basic survival curve using the data
fit <- survfit(survival ~ 1, data = net_lixx)
# Plot the survival curve and add a title!
plot(fit, lty = 1, mark.time = FALSE, ylim=c(.75,1), xlab = 'Days since Subscribing', ylab = 'Percent Surviving')
title(main = 'NetLixx Survival Curve')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment