Skip to content

Instantly share code, notes, and snippets.

@daynebatten
Created February 11, 2015 00:24
Show Gist options
  • Save daynebatten/0b77da1fda605475d329 to your computer and use it in GitHub Desktop.
Save daynebatten/0b77da1fda605475d329 to your computer and use it in GitHub Desktop.
# Run basic setup again
library(survival)
net_lixx <- read.csv('C:/Users/dayne/Desktop/NetLixx.csv')
net_lixx$survival <- Surv(net_lixx$time, net_lixx$churned == 1)
# Fit survival curves based on the female binary
fit <- survfit(survival ~ female, data = net_lixx)
# Plot the results, add a legend, add a title
plot(fit, lty = 1:2, mark.time = FALSE, ylim=c(.75,1), xlab = 'Days since Subscribing', ylab = 'Percent Surviving')
legend(20, .8, c('Male', 'Female'), lty=1:2, bty = 'n', ncol = 2)
title(main = "NetLixx Survival Curves by Gender")
# And run a log-rank test
survdiff(survival ~ female, data = net_lixx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment