Kaplan-Meyer Survival analysis

#survival analysis

import pandas as pd

from lifelines.estimation import KaplanMeierFitter

import matplotlib.pyplot as plt

kmf = KaplanMeierFitter()

df = pd.read_csv(‘intervened.csv’)

T = df[‘time’]

N = df[‘delta’]

df2 = pd.read_csv(‘not_intervened.csv’)

T2 = df2[‘time’]

N2 = df2[‘delta’]

ax = plt.subplot(111)

kmf.fit(T, event_observed=N, label=[‘intervened’])
kmf.survival_function_.plot(ax=ax)
kmf.fit(T2, event_observed=N2, label=[‘control’])
kmf.survival_function_.plot(ax=ax)

plt.title(‘Lifespans’)

kmf2 = plt.gcf()

plt.show()

#Logrank test

from lifelines.statistics import logrank_test
summary_= logrank_test(T, T2, N, N2, alpha=.99)

print summary_

ref)

https://en.wikipedia.org/wiki/Aneuploidy

http://c4s.blog72.fc2.com/blog-entry-84.html

https://plot.ly/ipython-notebooks/survival-analysis-r-vs-python/

http://dr-urashima.jp/pdf/how-kapuran.pdf

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s