Draw survival curves beginning at time 0

This commit is contained in:
RunasSudo 2023-04-16 23:53:04 +10:00
parent f1e943ca89
commit 847ec85083
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A

View File

@ -89,8 +89,9 @@ def plot_survfunc_kaplanmeier(ax, time, status, ci, transform_x=None, transform_
sf = sm.SurvfuncRight(time, status) sf = sm.SurvfuncRight(time, status)
# Draw straight lines # Draw straight lines
xpoints = sf.surv_times.repeat(2)[1:] # np.concatenate(...) to force starting drawing from time 0, survival 100%
ypoints = sf.surv_prob.repeat(2)[:-1] 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] handle = ax.plot(xpoints, ypoints)[0]
if transform_x: 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 ci1 = sf.surv_prob + zstar * sf.surv_prob_se
# Plot confidence intervals # Plot confidence intervals
ypoints0 = ci0.repeat(2)[:-1] ypoints0 = np.concatenate([[1], ci0]).repeat(2)[:-1]
ypoints1 = ci1.repeat(2)[:-1] ypoints1 = np.concatenate([[1], ci1]).repeat(2)[:-1]
if transform_y: if transform_y:
ypoints0 = transform_y(ypoints0) ypoints0 = transform_y(ypoints0)