| Title: | Survival Model Validation Utilities |
|---|---|
| Description: | Provides helper functions to compute linear predictors, time-dependent ROC curves, and Harrell's concordance index for Cox proportional hazards models. |
| Authors: | Minhyuk Kim [aut, cre] |
| Maintainer: | Minhyuk Kim <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-05-28 09:24:20 UTC |
| Source: | https://github.com/newjoseph/survc |
This helper wraps stats::predict() for coxph objects so that package users
can easily obtain linear predictors (default) or risk scores to feed into
downstream metrics such as time-dependent ROC or Harrell's C-index.
calc_risk_score(model, data = NULL, type = "lp", ...)calc_risk_score(model, data = NULL, type = "lp", ...)
model |
A fitted |
data |
Optional dataset on which to score the model. Defaults to the
training data stored within |
type |
Scale of the predictions to return. Either |
... |
Additional arguments passed to |
A numeric vector containing the requested risk scores.
if (requireNamespace("survival", quietly = TRUE)) { fit <- survival::coxph(survival::Surv(time, status) ~ age, data = survival::lung) # Linear predictor on the training data calc_risk_score(fit) # Risk scale predictions on new data calc_risk_score(fit, survival::lung, type = "risk") }if (requireNamespace("survival", quietly = TRUE)) { fit <- survival::coxph(survival::Surv(time, status) ~ age, data = survival::lung) # Linear predictor on the training data calc_risk_score(fit) # Risk scale predictions on new data calc_risk_score(fit, survival::lung, type = "risk") }
Calculate Harrell's C-index with 95% CI
cindex_calc(model, newdata = NULL, digits = 3)cindex_calc(model, newdata = NULL, digits = 3)
model |
a 'coxph' object |
newdata |
optional validation dataset |
digits |
number of decimal places for rounding (default 3). |
numeric vector of C-index (lower, upper)
library(survival) fit <- coxph(Surv(time, status) ~ age + sex, data = lung) cindex_calc(fit)library(survival) fit <- coxph(Surv(time, status) ~ age + sex, data = lung) cindex_calc(fit)
Calculate time-dependent ROC and AUC
tdroc_calc(time, status, marker, times)tdroc_calc(time, status, marker, times)
time |
Survival time vector |
status |
Event indicator (1 = event, 0 = censor) |
marker |
Risk score or linear predictor |
times |
Vector of time points (e.g., c(365, 730, 1095)) |
A data.frame with AUCs for each time
Generate survival model validation report
validation_report( train_data, val_data, model, time_col, status_col, times = c(365, 730, 1095), time_unit = "days", output = "validation_report.pptx" )validation_report( train_data, val_data, model, time_col, status_col, times = c(365, 730, 1095), time_unit = "days", output = "validation_report.pptx" )
train_data |
training dataset containing survival outcomes. |
val_data |
validation dataset containing survival outcomes. |
model |
fitted 'coxph' |
time_col |
name of the survival time column present in both datasets |
status_col |
name of the event indicator column present in both datasets |
times |
follow-up timepoints |
time_unit |
character label for the time axis (default = "days") |
output |
file path (.pptx or .html) |
Writes validation report