MyNixOS website logo
Description

Survival Model Validation Utilities.

Provides helper functions to compute linear predictors, time-dependent ROC curves, and Harrell's concordance index for Cox proportional hazards models as described in Therneau (2024) <https://CRAN.R-project.org/package=survival>, Therneau and Grambsch (2000, ISBN:0-387-98784-3), Hung and Chiang (2010) <doi:10.1002/cjs.10046>, Uno et al. (2007) <doi:10.1198/016214507000000149>, Blanche, Dartigues, and Jacqmin-Gadda (2013) <doi:10.1002/sim.5958>, Blanche, Latouche, and Viallon (2013) <doi:10.1007/978-1-4614-8981-8_11>, Harrell et al. (1982) <doi:10.1001/jama.1982.03320430047030>, Peto and Peto (1972) <doi:10.2307/2344317>, Schemper (1992) <doi:10.2307/2349009>, and Uno et al. (2011) <doi:10.1002/sim.4154>.

survC

R-CMD-check Coveragestatus Codecov testcoverage

survC provides lightweight utilities for validating survival models. The package focuses on Cox regression workflows, wrapping common validation tasks such as extracting linear predictors, computing Harrell’s concordance, and summarising time-dependent ROC curves. It also includes helpers for preparing cohort data and producing slide-based validation reports.

Installation

Install the development version of survC from GitHub with:

# install.packages("pak")
pak::pak("newjoseph/survC")

The examples below require the survival, timeROC, officer, and rvg packages. They are listed in Imports and will be pulled in automatically when survC is installed.

Key features

  • Convert fitted coxph models into linear predictors or risk scores with calc_risk_score() for downstream metrics.
  • Summarise time-dependent ROC curves across custom horizons via tdroc_calc() and inspect the underlying timeROC object.
  • Compute Harrell’s C-index (with a 95% confidence interval) for training or validation cohorts using cindex_calc().
  • Generate multi-slide PowerPoint reports that compare training and validation ROC curves at designated time points with validation_report(), specifying which columns contain survival times and event indicators.

Quick start

The example below demonstrates a typical validation workflow using the survival::lung dataset.

library(survC)
library(survival)

set.seed(2024)
lung <- survival::lung
lung <- lung[complete.cases(lung[, c("time", "status", "age", "ph.ecog")]), ]

# Split into training and validation cohorts
split_ids <- sample(seq_len(nrow(lung)))
train_idx <- split_ids[1:110]
val_idx <- split_ids[111:200]

train_df <- lung[train_idx, ]
val_df <- lung[val_idx, ]

# Fit a simple Cox model on the training data
cox_fit <- survival::coxph(
  survival::Surv(time, status == 2) ~ age + ph.ecog,
  data = train_df,
  x = TRUE
)

# 1. Linear predictor / risk scores
train_lp <- calc_risk_score(cox_fit)
val_lp <- calc_risk_score(cox_fit, data = val_df)

# 2. Harrell's concordance on the validation cohort
c_index_val <- cindex_calc(cox_fit, newdata = val_df)
c_index_val
#> Cindex  Lower  Upper 
#>  0.561  0.481  0.641

# 3. Time-dependent ROC summary at selected horizons
horizons <- c(200, 400)
roc_tbl <- tdroc_calc(
  time = val_df$time,
  status = as.integer(val_df$status == 2),
  marker = val_lp,
  times = horizons
)
roc_tbl
#>       time       AUC
#> t=200  200 0.5981693
#> t=400  400 0.5054571

The returned AUC table mirrors timeROC output and carries the full ROC object as the roc_obj attribute for plotting or inspection:

roc_obj <- attr(roc_tbl, "roc_obj")
list(
  AUC = roc_obj$AUC,
  times = roc_obj$times
)
#> $AUC
#>     t=200     t=400 
#> 0.5981693 0.5054571 
#> 
#> $times
#> [1] 200 400

Validation report (PowerPoint)

Use validation_report() to export one slide per horizon with training and validation ROC curves side-by-side. Pass the column names that hold follow-up times and event indicators via time_col and status_col. The function relies on officer and rvg so plots remain editable.

validation_report(
  train_data = transform(train_df, time = time, status = as.integer(status == 2)),
  val_data = transform(val_df, time = time, status = as.integer(status == 2)),
  model = cox_fit,
  time_col = "time",
  status_col = "status",
  times = horizons,
  time_unit = "days",
  output = "validation_report.pptx"
)

Development

Re-knit the README after editing with:

devtools::build_readme()

This regenerates README.md so GitHub reflects the latest examples.

Metadata

Version

0.1.0

License

Unknown

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows