pa_sample_design: Summarize multiple two-phase (case-cohort) models into a wide...

View source: R/pa_evaluate_two_phase.R

pa_sample_designR Documentation

Summarize multiple two-phase (case-cohort) models into a wide table

Description

For a list of models (each providing 'time', 'status', 'surv_prob', 'pred'), calls 'pa_evaluate_two_phase()' for each and returns a wide comparison table with metrics as rows and model names as columns.

Usage

pa_sample_design(
  models,
  case_weights,
  km_cens,
  metrics = c("pseudo_r2", "harrell_c", "uno_c", "brier_score", "td_auc", "ici"),
  t_star = NULL,
  tau = NULL,
  digits = 2,
  calibration_args = list()
)

Arguments

models

A **named list** in which each element corresponds to a fitted model. Each model entry must itself be a list containing:

  • times – numeric vector of observed follow-up times.

  • surv_prob – an n \times K matrix (or data frame) of subject-specific predicted survival probabilities on a common time grid.

  • status – event indicator (1 = event, 0 = censored).

  • pred – (optional) predicted mean survival time (restricted or unrestricted).

  • new_data – (optional) dataset used for prediction.

  • covs – character vector of covariate names used for prediction.

  • model – (optional) the underlying fitted survival model object.

Note: If pred is provided, it will be used to calculate R2 and concordance measure.

case_weights

Numeric vector of inverse-inclusion sampling weights, aligned with each model's evaluation subjects.

km_cens

A Kaplan-Meier fit for censoring (based on training data) used to compute IPCW.

metrics

Character vector of metrics to compute (default shown below).

t_star

Optional numeric scalar, specify the time point to evaluate Brier score and AUC.Default is median of observation time.

tau

Optional numeric scalar, specify the max time horizon for R2 measure and concordance measure (default = 10e10).

digits

Integer number of decimal places to round values (default 2).

calibration_args

Optional named list passed to [pa_calibration()], e.g. list(nk = 3). Weights come from case_weights.

Value

A data.frame: rows = metrics, columns = model names.

Examples

d <- pa_sim_cox_weibull(n = 150, pi_c = 0.3, v = 2,
                        beta = c(0.5, -0.5), seed = 2025)
d <- d[, c("time", "status", "x1", "x2")]
fit <- survival::coxph(survival::Surv(time, status) ~ x1 + x2,
                       data = d, x = TRUE, y = TRUE)
pred <- pa_predict_coxph(model = fit, covs = c("x1", "x2"), new_data = d)

# case-cohort sampling weights, and the censoring distribution they need
set.seed(2025)
in_subcohort <- stats::rbinom(nrow(d), 1, 0.4) == 1
w <- pa_case_cohort_weights(d$time, d$status, subcohort = in_subcohort)
keep <- which(in_subcohort | d$status == 1)
keep <- keep[order(d$time[keep])]
pred <- pa_predict_coxph(fit, c("x1", "x2"), new_data = d[keep, ])
w <- w[keep]
km <- survival::survfit(survival::Surv(d$time, 1 - d$status) ~ 1)

# the wide summary of the same two-phase evaluation
pa_sample_design(models = list(cc = pred), case_weights = w, km_cens = km)

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