Learn R Programming

survC (version 0.1.0)

calc_risk_score: Compute risk scores from a fitted survival model

Description

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.

Usage

calc_risk_score(model, data = NULL, type = "lp", ...)

Value

A numeric vector containing the requested risk scores.

Arguments

model

A fitted coxph object.

data

Optional dataset on which to score the model. Defaults to the training data stored within model.

type

Scale of the predictions to return. Either "lp" (linear predictor, the default) or "risk". If NULL or omitted, "lp" is used.

...

Additional arguments passed to stats::predict().

Examples

Run this code
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")
}

Run the code above in your browser using DataLab