Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lifelines/fitters/coxph_fitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ def fit(

"""
self.strata = utils._to_list_or_singleton(utils.coalesce(strata, self.strata))
self.formula = formula
self._model = self._fit_model(
df,
duration_col,
Expand Down Expand Up @@ -858,6 +859,7 @@ def compute_followup_hazard_ratios(self, training_df: DataFrame, followup_times:
weights_col=self.weights_col,
cluster_col=self.cluster_col,
entry_col=self.entry_col,
formula=self.formula,
)
results[t] = model.hazard_ratios_
return DataFrame(results).T
Expand Down
8 changes: 8 additions & 0 deletions lifelines/tests/test_estimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3248,6 +3248,14 @@ def test_compute_followup_hazard_ratios(self, cph, cph_spline, rossi):
cph_spline.fit(rossi, "week", "arrest")
cph_spline.compute_followup_hazard_ratios(rossi, [15, 25, 35, 45])

def test_compute_followup_hazard_ratios_preserves_formula(self, cph, rossi):
cph.fit(rossi, "week", "arrest", formula="fin + age + race")

result = cph.compute_followup_hazard_ratios(rossi, [rossi["week"].max()])

assert_index_equal(result.columns, cph.hazard_ratios_.index)
assert_series_equal(result.iloc[0], cph.hazard_ratios_, check_names=False)

def test_model_can_accept_null_covariates(self, cph, rossi):
cph.fit(rossi[["week", "arrest"]], "week", "arrest")
assert True
Expand Down