pa_calibration: Calibration of Predicted Event Probabilities at One Time...

View source: R/pa_calibration.R

pa_calibrationR Documentation

Calibration of Predicted Event Probabilities at One Time Point

Description

Assess calibration from externally supplied probabilities and observed outcomes, without requiring the original prediction model.

Usage

pa_calibration(p, event_time, status, t_star, nk = 5, case_weights = NULL)

pa_calibration_cr(
  p,
  event_time,
  status,
  t_star,
  event_type = 1,
  bandwidth = NULL
)

Arguments

p

Numeric vector of predicted event probabilities at t_star, in the same subject order as event_time and status. For ordinary survival supply 1 - S(t_star); for competing risks supply the CIF of event_type at t_star.

event_time

Numeric vector of finite, non-negative observed times.

status

Event indicators: 0 for censoring and 1 for an event in pa_calibration(); non-negative integer event codes in pa_calibration_cr() (0 for censoring).

t_star

One positive finite evaluation time, not exceeding the maximum observed follow-up. Use the same time units as event_time.

nk

Number of restricted cubic spline knots (at least 3; default 5).

case_weights

Optional positive finite inverse-inclusion sampling weights, aligned with the subjects. For pa_calibration() only. Used in both the calibration model and the metric summaries.

event_type

Positive integer code for the cause of interest.

bandwidth

Nearest-neighborhood smoothing bandwidth passed to prodlim::prodlim(). NULL uses its automatic bandwidth.

Details

pa_calibration() uses pmcalibration::pmcalibration() with a restricted cubic spline and no confidence interval computation. The knot count is capped at the number of distinct fitting probabilities; with fewer than five distinct probabilities or fewer than six subjects it uses the backend's single-predictor Cox calibration instead. Constant predictions are compared with the marginal Kaplan–Meier risk.

The right-censored backend requires probabilities strictly inside (0, 1). Probabilities within sqrt(.Machine$double.eps) of 0 or 1 are clipped to that distance from the boundary for fitting, with a warning (except for the constant-prediction Kaplan–Meier branch). Metrics compare calibrated values with the original probabilities and retain every subject.

pa_calibration_cr() uses local Aalen–Johansen estimates from prodlim, conditional on the predicted CIF. All nonzero causes other than event_type are pooled as competing events, not censored. Constant or few-valued predictions use the backend's discrete risk groups. This is a different curve estimator from Fine–Gray spline calibration.

For unweighted evaluations, both functions use pmcalibration::cal_metrics() to summarize absolute differences between predicted and curve-implied probabilities at the original subjects. Only ici (the backend's Eavg), e50, and e90 are returned. They are probability-scale errors, with 0 ideal. ICI averages over subjects, not over follow-up time or a uniform risk grid.

With case_weights, pa_calibration() fits a sampling-weighted Cox model directly, using the same complementary log-log transformation and restricted cubic spline knot-placement rule as the ordinary backend. Both coefficients and baseline cumulative hazard come from the weighted fit. Constant predictions use weighted Kaplan–Meier risk; with fewer than five distinct fitting probabilities or six subjects a single linear predictor is used. Knot locations are recorded in knots. ICI is the normalized sampling-weighted mean absolute error. E50 and E90 use weighted order-statistic interpolation, with weights normalized to the sample size (Hmisc::wtd.quantile(..., normwt = TRUE)). Multiplying every sampling weight by the same constant has no effect.

Supply subject inclusion weights for the actual case–cohort/NCC design, rather than weights already combined with censoring adjustments. Only sampled subjects with positive inclusion probabilities should be supplied. The calibration Cox model assumes conditionally independent censoring given its predictor and an appropriate proportional-hazards spline relationship. The competing-risks function remains an unweighted cohort evaluation. No optimism correction or design-based confidence interval is applied; preferably supply held-out or out-of-fold predictions.

Value

A list with metrics, a named numeric vector c(ici, e50, e90); curve, a data frame with predicted and calibrated probabilities in input subject order; t_star; event_type; and method, the curve estimator. Weighted results also include the original case_weights and spline knots on the complementary log-log scale (empty for simpler fits).

References

Austin PC, Steyerberg EW (2019). The Integrated Calibration Index (ICI) and related metrics for quantifying the calibration of logistic regression models. Statistics in Medicine 38, 4051–4065. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/sim.8281")}. Austin PC, Harrell FE Jr, van Klaveren D (2020). Graphical calibration curves and the integrated calibration index (ICI) for survival models. Statistics in Medicine 39, 2714–2742. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1002/sim.8570")}. Breslow NE, Wellner JA (2007). Weighted likelihood for semiparametric models and two-phase stratified samples, with application to Cox regression. Scandinavian Journal of Statistics 34, 86–102. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.1467-9469.2006.00523.x")}. Samuelsen SO (1997). A pseudolikelihood approach to analysis of nested case-control studies. Biometrika 84, 379–394. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/84.2.379")}.

Examples

set.seed(19)
x <- stats::rnorm(100)
event <- stats::rexp(100, rate = exp(x))
censor <- stats::rexp(100, rate = 0.3)
time <- pmin(event, censor)
status <- as.integer(event <= censor)
p <- 1 - exp(-exp(x) * 0.5)
pa_calibration(p, time, status, t_star = 0.5)$metrics

# Externally supplied CIFs; no fitted model object is needed.
competing <- stats::rexp(100, rate = 0.4)
cr_time <- pmin(event, competing, censor)
cr_status <- ifelse(censor < pmin(event, competing), 0L,
                    ifelse(event <= competing, 1L, 2L))
cif <- exp(x) / (exp(x) + 0.4) * (1 - exp(-(exp(x) + 0.4) * 0.5))
pa_calibration_cr(cif, cr_time, cr_status, t_star = 0.5)$metrics

PAmeasures documentation built on Oct. 29, 2026, 1:08 a.m.