Skip to content

Preserve formulas in follow-up hazard-ratio refits - #1703

Open
dnncha wants to merge 2 commits into
CamDavidsonPilon:masterfrom
dnncha:fix/followup-hazard-ratios-formula
Open

dnncha wants to merge 2 commits into
CamDavidsonPilon:masterfrom
dnncha:fix/followup-hazard-ratios-formula

Conversation

@dnncha

@dnncha dnncha commented Sep 27, 2026

Copy link
Copy Markdown

ELI5: follow-up hazard ratios could come from a different Cox model than the one the user fitted. Formula-based fits silently expanded to every eligible dataframe column.

This forwards the saved formula when compute_followup_hazard_ratios() refits at each follow-up time.

Example

On the bundled Rossi data, a model fitted with formula="fin + age + race" returned seven terms from this method. At week 52, the reported race hazard ratio was 1.368753 instead of the fitted model's 1.300095.

Test

The regression test checks two contracts at maximum follow-up:

  • returned terms equal the original formula's terms;
  • hazard ratios equal the original fitted model.
python -m pytest -q lifelines/tests/test_estimation.py -k compute_followup_hazard_ratios
# 2 passed

The existing no-formula path remains covered and passes.

Fixes #1702

Limits: this fixes model specification and numerical output. It does not identify an affected publication or establish a changed scientific conclusion.

@dnncha dnncha closed this Sep 27, 2026
@dnncha dnncha reopened this Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compute_followup_hazard_ratios drops a fitted formula

1 participant