feat(competing-risks): add FineGrayFitter -- Fine & Gray (1999) subdistribution hazard - #1689
Open
hass-nation wants to merge 2 commits into
Open
Conversation
…ion hazard model Implements Fine-Gray (1999) competing-risks regression, the standard model for estimating covariate effects on the cumulative incidence function (CIF) when competing events are present. New class FineGrayFitter: - Two-step IPCW partial likelihood (Fine & Gray 1999) - Modified risk set: competing-event subjects re-enter with IPCW weight G(Ti)/G(t), where G is the KM censoring survival - Newton-Raphson optimisation with Hessian-based convergence check - Breslow baseline subdistribution hazard estimator - Predicted CIF: F(t|x) = 1 - exp(-exp(x'beta) * Lambda0(t)) - Standard errors from observed Fisher information - predict_cumulative_incidence(), predict_partial_hazard() - plot_partial_effects_on_outcome(), print_summary() - AIC_partial_, BIC_partial_, log_likelihood_ Added to lifelines.__init__ and __all__. 55 tests across 8 test classes; 0 regressions on existing suite. References ---------- Fine, J. P. and Gray, R. J. (1999). A proportional hazards model for the subdistribution of a competing risk. Journal of the American Statistical Association, 94(446):496-509. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Three bugs found during test run on current lifelines main: 1. Printer API changed: now takes positional List[Tuple] args, not kwargs. Updated print_summary() to use the current Printer(model, headers, footers, justify, header_kwargs, decimals, columns) signature. 2. Printer internally calls self.model.summary — added summary @Property returning the full coefficient table (coef, exp(coef), se(coef), z, p, CI bounds, cmp to, -log2(p)) matching the columns Printer expects. 3. test_equal_weights_same_as_no_weights was adding 'w' to both DataFrames before the unweighted fit, causing 'w' to appear as a covariate. Fixed by using separate df / df_w variables. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
FineGrayFitter— the Fine & Gray (1999) proportional subdistribution hazard model for competing risks. This is the most widely-used regression approach for competing risks data, implemented in R ascmprsk::crr, but not yet available in lifelines.Closes the long-standing feature request for competing-risks regression (issue #619, issue #539).
Why Fine-Gray?
The existing
AalenJohansenFittergives the non-parametric CIF estimate, but offers no way to model covariate effects. UsingCoxPHFitteron competing-risks data (treating competing events as censored) over-estimates the CIF and gives coefficients on the wrong quantity. Fine-Gray directly models the subdistribution hazard, which maps one-to-one to the CIF.Model
The subdistribution hazard for cause k:
Related to the CIF by:
Algorithm (Fine & Gray 1999):
New Public API
Output:
Files added / changed
lifelines/fitters/fine_gray_fitter.pyFineGrayFitterclass (~480 lines)lifelines/tests/test_fine_gray.pylifelines/__init__.py__all__entryTests
Test coverage:
__all__membershipNo new dependencies
Only NumPy, SciPy, and pandas — already required by lifelines. Uses the existing
KaplanMeierFitterfor censoring estimation.References
Generated with Claude Code