Repository navigation
Fine-Gray rows in cox and cox_counting models, without expanding rows - #125
Merged
Merged
Conversation
convertToCyclopsData(..., fineGrayCensoring = data.frame(fineGrayGroup, time, survival)) with an outcome column fineGrayGroup: a row of group g > 0 ended with a competing event at its stop time T and stays in the risk set of every later event time t of its stratum, its weight multiplied by G_g(t-) / G_g(T-). CountingProcessModelSpecifics keeps one running sum per group in each risk set, so a fit is O(rows + event times x groups). Covered: denominators and log likelihood, CCD gradient and Hessian, Fisher information (vcov), robust score contributions, Schoenfeld residuals, separation checks, cross-validation, and the second-order API (gradient, Hessian block, Hv, trial/commit, Woodbury) for dense and CG Newton steps. predict(times = ) and survfit() stop with an error; third derivatives throw; double precision only. Tests (test-fineGrayCounting.R, 58 expectations) compare every fit with the cox_counting fit on the expanded rows. NEWS 49. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NEWS: develop's #124 took items 49-51; the Fine-Gray item is 52. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #125 +/- ##
===========================================
+ Coverage 85.87% 86.03% +0.15%
===========================================
Files 73 73
Lines 16338 16690 +352
===========================================
+ Hits 14031 14359 +328
- Misses 2307 2331 +24 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
Fine-Gray (subdistribution hazard) models in
coxandcox_counting, with counting-process data, case weights and one censoring distribution per group, without expanding rows.A row with
fineGrayGroupg > 0 ended with a competing event at its stop time T. It stays in the risk set of every later event time t of its stratum, with its weight multiplied by G_g(t−) / G_g(T−). G_g is the right-continuous step function of group g infineGrayCensoring, and 1 for a group with no rows there.Why
CloneCensorWeight's Fine-Gray MSM needs time-varying clone weights, which means (start, stop] segments, and a censoring distribution per strategy.
fgrtakes one right-censored row per subject, a fixed weight and a single G, so CCW has been expanding the rows itself: one extra row per competing death and later jump of G. That is about 4.3× the segments on simulated data, and the count grows as deaths × follow-up days.How
CountingProcessModelSpecificstreats each competing-event row as having a "tail": the groups of its stratum after its stop time. Each risk-set sum becomesS(i) = (ordinary rows) + Σ_g m_g(i) · (running sum of group g's tails),
with m_g(i) = G_g(t_i−) and a per-row factor 1 / G_g(T−). A fit is then O(rows + event times × groups).
The tails are included in:
vcov()), the robust score contributions (vcov(type = "robust")) and the Schoenfeld residuals;fullGradient,hessianBlock,hessianVector,trialLogLikelihood/commitStep, andwoodburyParts. So dense and conjugate-gradient Newton steps, with or without the Woodbury preconditioner, work.Tails that run to the end of their stratum exit at the unused group N, so running sums never leak into the next stratum.
Not implemented, and refused rather than wrong:
predict(times = )andsurvfit()stop with an error;Rows without
fineGrayGrouptake the existing code paths unchanged.Tests
tests/testthat/test-fineGrayCounting.R: 10 tests, 58 expectations, 2.2 s. Every comparison is against thecox_countingfit on the explicitly expanded rows:vcov(1e-7), with and without strata, with case weights and (start, stop] rows;ccd,newtonandauto, at 1 and 4 threads; a Laplace prior;.cyclopsSecondOrder(): gradient, Hessian, Hv, trial and committed log-likelihood (1e-9), at 1 and 4 threads;survfit()refused.Full suite (
NOT_CRAN, installed package, on the merge with develop 4130cc1): 381 tests, 2,043 expectations, 0 failed; the 8 file-level errors (test-bootstrap, conditionalPoisson, dataConversionStratified/Unstratified, fisherEvents, smallCLR, smallFineGray, weighting) are the same as on develop.In CloneCensorWeight (branch
ccw-v2-finegray, not pushed), thefineGrayMSM uses these rows when the installed Cyclops has them. At 10^5 simulated persons it takes 2.1 s instead of 11.3 s, fitting 1.0M segments instead of 4.3M expanded rows, with the same SHR and SE. The CCW default tier passes (5,819 expectations).NEWS item 52. develop's #124 took 49–51, merged in here.
🤖 Generated with Claude Code