Skip to content

Commit

Permalink
Merge pull request #1 from rvdinter/cox-tv-survival-function
Browse files Browse the repository at this point in the history
survival function for cox tv
  • Loading branch information
rvdinter authored Sep 17, 2024
2 parents d875d25 + a6016e8 commit 637c23c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lifelines/fitters/cox_time_varying_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,15 @@ def _compute_confidence_intervals(self):
index=self.params_.index,
)

def calculate_survival_function(self, X: pd.DataFrame) -> pd.Series:
v = self.predict_partial_hazard(X)
col = utils._get_index(v)
times_ = X.start.values
c_0 = utils.interpolate_at_times(self.baseline_cumulative_hazard_, [times_]).T
cumulative_hazard_ = pd.DataFrame(c_0 * v.values, columns=col, index=times_)
surv_func = pd.Series(np.exp(-cumulative_hazard_).values.diagonal(), index=times_)
return surv_func

@property
def summary(self):
"""Summary statistics describing the fit.
Expand Down

0 comments on commit 637c23c

Please sign in to comment.