From 847ec85083120b84e0e14d67ce652ed2ffb91e43 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 16 Apr 2023 23:53:04 +1000 Subject: [PATCH] Draw survival curves beginning at time 0 --- yli/survival.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/yli/survival.py b/yli/survival.py index ed27489..710caf9 100644 --- a/yli/survival.py +++ b/yli/survival.py @@ -89,8 +89,9 @@ def plot_survfunc_kaplanmeier(ax, time, status, ci, transform_x=None, transform_ sf = sm.SurvfuncRight(time, status) # Draw straight lines - xpoints = sf.surv_times.repeat(2)[1:] - ypoints = sf.surv_prob.repeat(2)[:-1] + # np.concatenate(...) to force starting drawing from time 0, survival 100% + xpoints = np.concatenate([[0], sf.surv_times]).repeat(2)[1:] + ypoints = np.concatenate([[1], sf.surv_prob]).repeat(2)[:-1] handle = ax.plot(xpoints, ypoints)[0] if transform_x: @@ -106,8 +107,8 @@ def plot_survfunc_kaplanmeier(ax, time, status, ci, transform_x=None, transform_ ci1 = sf.surv_prob + zstar * sf.surv_prob_se # Plot confidence intervals - ypoints0 = ci0.repeat(2)[:-1] - ypoints1 = ci1.repeat(2)[:-1] + ypoints0 = np.concatenate([[1], ci0]).repeat(2)[:-1] + ypoints1 = np.concatenate([[1], ci1]).repeat(2)[:-1] if transform_y: ypoints0 = transform_y(ypoints0)