View source: R/pa_evaluate_two_phase.R
| pa_sample_design | R Documentation |
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.
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()
)
models |
A **named list** in which each element corresponds to a fitted model. Each model entry must itself be a list containing:
Note: If |
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. |
A data.frame: rows = metrics, columns = model names.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.