A function to compute the Harrell's concordance index of a survival model.
c_index(y_true = NULL, risk = NULL, surv = NULL, times = NULL)
a survival::Surv
object containing the times and statuses of observations for which the metric will be evaluated
a numeric vector of risk scores corresponding to each observation
ignored, left for compatibility with other metrics
ignored, left for compatibility with other metrics
numeric from 0 to 1, higher values indicate better performance
[1] Harrell, F.E., Jr., et al. "Regression modelling strategies for improved prognostic prediction." Statistics in Medicine 3.2 (1984): 143-152.
# \donttest{
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)
#> Preparation of a new explainer is initiated
#> -> model label : coxph ( default )
#> -> data : 2982 rows 12 cols ( extracted from the model )
#> -> target variable : 2982 values ( 1518 events and 1464 censored , censoring rate = 0.491 ) ( extracted from the model )
#> -> times : 51 unique time points , min = 43.5 , median survival time = 2983 , max = 6258
#> -> times : ( generated from y as uniformly distributed survival quantiles based on Kaplan-Meier estimator )
#> -> predict function : predict.coxph with type = 'risk' will be used ( default )
#> -> predict survival function : predictSurvProb.coxph will be used ( default )
#> -> predict cumulative hazard function : -log(predict_survival_function) will be used ( default )
#> -> model_info : package survival , ver. 3.7.0 , task survival ( default )
#> A new explainer has been created!
risk <- coxph_explainer$predict_function(coxph_explainer$model, coxph_explainer$data)
c_index(y_true = coxph_explainer$y, risk = risk)
#> [1] 0.8633358
# }