From 5f4ab2216d69c5de351d64711c534e999d456232 Mon Sep 17 00:00:00 2001 From: Daniel Chen Date: Fri, 21 Jul 2017 21:24:20 -0500 Subject: [PATCH] add code for cox assumption plot adds python code for the first plot in the "Checking the proportional hazards assumption" section fixes #322 --- docs/Survival Regression.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/docs/Survival Regression.rst b/docs/Survival Regression.rst index b059fdf02..8216dc333 100644 --- a/docs/Survival Regression.rst +++ b/docs/Survival Regression.rst @@ -455,6 +455,30 @@ A quick and visual way to check the proportional hazards assumption of a variabl The following is the loglogs curves of two variables in our regime dataset. The first is the democracy type, which does have (close to) parallel lines, hence satisfies our assumption: +.. code:: python + + from lifelines.datasets import load_dd + from lifelines import KaplanMeierFitter + + data = load_dd() + + democracy_0 = data.loc[data['democracy'] == 'Non-democracy'] + democracy_1 = data.loc[data['democracy'] == 'Democracy'] + + kmf0 = KaplanMeierFitter() + kmf0.fit(democracy_0['duration'], event_observed=democracy_0['observed']) + + kmf1 = KaplanMeierFitter() + kmf1.fit(democracy_1['duration'], event_observed=democracy_1['observed']) + + fig, axes = plt.subplots() + kmf0.plot_loglogs(ax=axes) + kmf1.plot_loglogs(ax=axes) + + axes.legend(['Non-democracy', 'Democracy']) + + plt.show() + .. image:: images/lls_democracy.png