Compute the Harrell's Concordance index
A function to compute the Harrell's concordance index of a survival model.
c_index(y_true = NULL, risk = NULL, surv = NULL, times = NULL)
y_true
: a survival::Surv
object containing the times and statuses of observations for which the metric will be evaluatedrisk
: a numeric vector of risk scores corresponding to each observationsurv
: ignored, left for compatibility with other metricstimes
: ignored, left for compatibility with other metricsnumeric from 0 to 1, higher values indicate better performance
library(survival) library(survex) rotterdam <- survival::rotterdam rotterdam$year <- NULL cox_rotterdam_rec <- coxph(Surv(rtime, recur) ~ ., data = rotterdam, model = TRUE, x = TRUE, y = TRUE ) coxph_explainer <- explain(cox_rotterdam_rec) risk <- coxph_explainer$predict_function(coxph_explainer$model, coxph_explainer$data) c_index(y_true = coxph_explainer$y, risk = risk)
loss_one_minus_c_index()