View source: R/pa_evaluate_two_phase.R
| pa_evaluate_two_phase | R Documentation |
This function constructs a standardized evaluation dataset ('dat1') from the analysis dataset, predicted survival probabilities, and sampling weights, and computes key performance metrics in a tidy table format. Works for common two-phase sampling designs: - Case-cohort (unstratified or stratified) - Nested case-control (matched or unmatched)
pa_evaluate_two_phase(
pred_results,
t_star = NULL,
tau = 1e+11,
km_cens_fit,
case_weights,
metrics = c("pseudo_r2", "harrell_c", "uno_c", "brier_score", "td_auc", "ici"),
calibration_args = list()
)
pred_results |
A prediction list, such as the output of
|
t_star |
(Optional) Evaluation time for Brier score, time-dependent AUC, and calibration. If NULL, it defaults to the median survival time. |
tau |
(Optional) A numeric value specifying the truncation time for calculating explained variation metrics. If NULL, it defaults to the maximum observed survival time. |
km_cens_fit |
Kaplan-Meier estimate of the censoring distribution, a 'survival::survfit' object. Not required when only calibration is requested. |
case_weights |
Numeric sampling weights in the same subject order as
|
metrics |
Character vector of metrics. |
calibration_args |
Optional named list of calibration settings,
e.g. |
Calibration uses the event risk from the last prediction-grid
column at or before t_star, with the exact requested outcome
horizon. Both the Cox spline calibration model and absolute-error
summaries use sampling weights; see [pa_calibration()].
Calibration-only inputs need times, status, and
surv_prob, without fitted models or mean time predictions.
A tibble with columns: - 'Metric': name of metric - 'Value': numeric value
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)
pa_evaluate_two_phase(pred_results = pred, km_cens_fit = km,
case_weights = w)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.