Skip to content

Cox survival prediction: weighted Breslow baseline and predict(fit, newCovariates, times) - #116

Merged
msuchard merged 4 commits into
developfrom
ccw-cox-predict
Nov 18, 2026
Merged

msuchard merged 4 commits into
developfrom
ccw-cox-predict

Conversation

@msuchard

Copy link
Copy Markdown
Member

Summary

Survival prediction for cox and cox_counting fits.

  • Weighted Breslow baseline: survfit() for cox and cox_counting fits uses the fit's case weights in event counts and risk sets (weight-0 rows left out), and gives one curve per stratum for cox fits too. Before, it used unweighted counts and ignored strata for cox.
  • predict(fit, newOutcomes, newCovariates, times = ) returns S(t | x) = exp(-Lambda0(t) exp(x'beta)) for new rows at times (a matrix, a row per rowId, a column per time), with each row's stratum baseline (stratumId) in stratified fits. It matches survfit(coxph(..., weights = , ties = "breslow"), newdata, ctype = 1, stype = 2). predict() on new Cox data previously stopped.
  • Both read the baseline from the fit's own interface and stop once another model has been fitted to the same Cyclops data (fits share that interface; survfit() silently mixed two fits before), unless that fit used forceNewObject = TRUE. Fit objects keep their weights.
  • NEWS item 39; tests in test-coxPredict.R.

Notes

Testing

On the merged tip (macOS arm64, R 4.6): full testthat suite with NOT_CRAN=true: 1881 expectations passed, 0 failed, 0 errors (18 skipped). R CMD check --as-cran --no-manual (_R_CHECK_FORCE_SUGGESTS_=false): Status OK.

🤖 Generated with Claude Code

msuchard and others added 4 commits November 16, 2026 15:37
survfit() for cox and cox_counting fits uses the case weights of the fit in
the event counts and risk sets of the Breslow baseline (rows with weight 0 are
left out) and gives one curve per stratum for cox fits too.
predict(fit, newOutcomes, newCovariates, times = ) returns S(t | x) of new rows
of cox and cox_counting fits, with the baseline of each row's stratumId in
stratified fits. Matches survfit(coxph(weights, ties = "breslow"), newdata,
ctype = 1, stype = 2) with and without weights, strata and counting process.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
predict() and survfit() of cox and cox_counting fits build the Breslow
baseline from the fit object: its stored weights (fit$weights) and the
linear predictors of its own interface, and stop when a later fit on the
same Cyclops data has replaced the fit's coefficients or weights there
(fits with forceNewObject = TRUE leave it alone). Before, they silently
mixed the old coefficients with the later fit's baseline.
New-data prediction for Cox stops for fits with non-numeric covariate
names (formula fits), which gave a linear predictor of 0. The data frame
path sorts rows by rowId when every coefficient is 0, as the other paths.
Tests for refits on the same data, zero-coefficient fits (data frames and
Andromeda) and the input checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NEWS: the Cox survival prediction item is 39. predict() for new Andromeda
outcomes keeps both stratumId (Cox) and offset (lr) columns; its help
keeps both the Cox and the lr offset details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@msuchard
msuchard merged commit 7cd8c08 into develop Nov 18, 2026
13 checks passed
@msuchard
msuchard deleted the ccw-cox-predict branch November 18, 2026 18:14
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.04545% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.12%. Comparing base (3ae9bb6) to head (e41185f).
⚠️ Report is 12 commits behind head on develop.

Files with missing lines Patch % Lines
R/Survfit.R 83.72% 7 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #116      +/-   ##
===========================================
- Coverage    85.21%   85.12%   -0.10%     
===========================================
  Files           73       73              
  Lines        15699    15760      +61     
===========================================
+ Hits         13378    13415      +37     
- Misses        2321     2345      +24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant