0

I’m trying to produce the predict survival function for censored subjects at their current time using this:

def predict_cumulative_hazard_at_single_time(self, X, times, ancillary_X=None):
        lambda_, rho_ = self._prep_inputs_for_prediction_and_return_scores(X, ancillary_X)
        return (times / lambda_) ** rho_


def predict_survival_function_at_single_time(self, X, times, ancillary_X=None):
        return np.exp(-self.predict_cumulative_hazard_at_single_time(X, times=times, ancillary_X=ancillary_X))


aft.predict_survival_function_at_single_time = predict_survival_function_at_single_time.__get__(aft)
aft.predict_cumulative_hazard_at_single_time = predict_cumulative_hazard_at_single_time.__get__(aft)

p_surv2 = aft.predict_survival_function_at_single_time(censored_subjects,
                                                  times=censored_subjects['CSI'])

But the results are different from when I add conditional_after:

survival = aft.predict_survival_function(censored_subjects,
                                    times=censored_subjects['CSI'],
                                    conditional_after=censored_subjects_last_obs)

How do I add a conditional_after for censored_subjects at their current time without creating an NxN output?

ywbaek
  • 2,971
  • 3
  • 9
  • 28

1 Answers1

0

If I understand correctly, you want each the survival function evaluated at each subject's censorship time? There is no vectorized way to do this, do you'll have to do a for-loop:

survival = pd.Series(index=censored_subjects.index)
for id in censored_subjects.index:
    survival.loc[id] = aft.predict_survival_function(
                      censored_subjects.loc[id],
                      times=censored_subjects.loc[id, 'CSI'],                               
                      conditional_after=censored_subjects_last_obs.loc[id]
                     )

(the above isn't guaranteed to run, just an example)

Cam.Davidson.Pilon
  • 1,606
  • 1
  • 17
  • 31