Return the RMST estimator's sampling variance (Greenwood, K&M eq. 4.4.4) from restricted_mean_survival_time for Kaplan-Meier fits - #1696
Open
azrabano23 wants to merge 1 commit into
Conversation
…ator's sampling variance for Kaplan-Meier fits restricted_mean_survival_time(..., return_variance=True) returned E[min(T,t)^2] - E[min(T,t)]^2, the variance of the truncated random variable -- a property of the distribution -- rather than the sampling variance of the RMST estimator, silently inflating standard errors and p-values built from it. For a KaplanMeierFitter fit to right-censored data, return the Greenwood-based sampling variance (Klein & Moeschberger 2003, eq. 4.4.4), matching R's survRM2::rmst2. For parametric fitters and precomputed survival functions, keep the previous value for backwards compatibility but emit a StatisticalWarning that it is not a sampling variance; document both behaviours in the docstring. Closes CamDavidsonPilon#1682
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.
Closes #1682
What was wrong
restricted_mean_survival_time(model, t, return_variance=True)returnedwhich is the variance of the truncated random variable min(T, t) — a property of the survival distribution itself — not the sampling variance of the RMST estimator. Anyone using it to build a standard error, confidence interval, or 2-sample z-test silently got grossly inflated SEs and conservative p-values. On the bundled
waltonsdata (miR-137 group, τ=10) the implied SE was ~0.719 where the correct SE is ~0.123 — the variance was ~34× too large, and a 2-sample test onwaltonsmoved from p≈0.81 to p≈0.15 once the correct variance is used (see #1682 for the full reproduction).The fix
For a
KaplanMeierFitterfit to right-censored data,return_variance=Truenow returns the Greenwood-based sampling variance of the RMST estimator, Klein & Moeschberger (2003), Survival Analysis: Techniques for Censored and Truncated Data, eq. 4.4.4:summed over distinct event times t_i ≤ τ, with d_i events out of n_i at risk (terms with n_i = d_i contribute 0, as in
survRM2). This is the same estimator R'ssurvRM2::rmst2uses. It's computed exactly frommodel.event_tableand the KM step function — no numerical integration.Backwards compatibility
StatisticalWarningis now emitted spelling out that this value is not a sampling variance and must not be used for SEs/CIs/tests, and the docstring documents both behaviours explicitly. (This follows the fallback suggested in restricted_mean_survival_time(..., return_variance=True) returns variance of the truncated RV, not the sampling variance — silently produces wrong p-values #1682; it also covers what warn when restricted_mean_survival_time(return_variance=True) is used #1683 set out to do for the non-KM paths.)Validation
waltonsmiR-137, τ=10: new result RMST = 9.794118, SE = 0.123245 — matches thesurvRM2::rmst2reference values reported in restricted_mean_survival_time(..., return_variance=True) returns variance of the truncated RV, not the sampling variance — silently produces wrong p-values #1682 (RMST 9.794, SE 0.123) and PR includes RMST, difference in RMST and confidence intervals #1526's fixture for the same case.lifelines/tests/utils/test_utils.pystill pass unchanged, including the truncated-RV variance test forExponentialFitter(test_rmst_variance) and the left-censoring edge case.