Repository navigation
Cox survival prediction: weighted Breslow baseline and predict(fit, newCovariates, times) - #116
Merged
Merged
Conversation
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>
Codecov Report❌ Patch coverage is
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. 🚀 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.
Summary
Survival prediction for
coxandcox_countingfits.survfit()forcoxandcox_countingfits uses the fit's case weights in event counts and risk sets (weight-0 rows left out), and gives one curve per stratum forcoxfits too. Before, it used unweighted counts and ignored strata forcox.predict(fit, newOutcomes, newCovariates, times = )returns S(t | x) = exp(-Lambda0(t) exp(x'beta)) for new rows attimes(a matrix, a row perrowId, a column per time), with each row's stratum baseline (stratumId) in stratified fits. It matchessurvfit(coxph(..., weights = , ties = "breslow"), newdata, ctype = 1, stype = 2).predict()on new Cox data previously stopped.survfit()silently mixed two fits before), unless that fit usedforceNewObject = TRUE. Fit objects keep theirweights.test-coxPredict.R.Notes
develop(including Pooled logistic regression (modelType = "plr"), lr offsets, and a configurable Newton memory budget #114); DESCRIPTION stays at 4.0.2. The merge combined Pooled logistic regression (modelType = "plr"), lr offsets, and a configurable Newton memory budget #114'slroffset handling inpredict()with this PR's Cox code: the Andromeda path now keeps bothstratumIdandoffsetcolumns ofnewOutcomes, and the help page keeps both details paragraphs.ccw-c6c7-fix) carries this PR, the refit API PR, and a fix for their interaction (Cox prediction afterupdateOutcomes()); merge it after both.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