When predicting for subjects who have already survived past a certain time $s$ (censored subjects), you must calculate the conditional survival function. This answers: What is the subject's new survival function given they have already lived until time $s$?
In lifelines, all prediction methods support the conditional_after keyword argument to handle this.
Important: When using conditional_after, the resulting metrics are conditional. For example, if predict_median returns 10.5, the predicted total lifetime is $10.5 + s$.
To predict the remaining life of censored subjects:
- Identify the censored subjects.
- Pass their last observed time as the
conditional_after argument.
# all regression models can be used here, WeibullAFTFitter is used for illustration
from lifelines import WeibullAFTFitter
from lifelines.datasets import load_rossi
rossi = load_rossi()
wf = WeibullAFTFitter().fit(rossi, "week", "arrest")
# filter down to just censored subjects to predict remaining survival
censored_subjects = rossi.loc[~rossi['arrest'].astype(bool)]
censored_subjects_last_obs = censored_subjects['week']
# predict new survival function
# the survival function is scaled by the survival at the conditional_after time
wf.predict_survival_function(censored_subjects, conditional_after=censored_subjects_last_obs)
# predict median remaining life
# result is the additional time expected after censored_subjects_last_obs
wf.predict_median(censored_subjects, conditional_after=censored_subjects_last_obs)