How to calculate the c-index directly from risk scores in R?

28 Views Asked by At

I am doing a survival analysis. Below are the risk scores I got based on the test set and the model:

risk_scores <- c(0.4995992, 0.5475576, 0.4896132, 0.5176351, 0.5111408, 0.5035943, 0.4995992, 0.4995992, 0.4935940, 0.4879983, 0.5176351, 0.4966655, 0.4995992, 0.4995920, 0.4896132, 0.5779451)

Then how to calculate the c-index directly from the risk scores in R?

Below are my status and time variables:

status <- c(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
time <- c(455, 210, 1022, 310, 361, 218, 166, 170, 567, 613, 707,  61, 301,  81, 371, 520)

I tried several packages on my end but their syntax confused me. Look forward to any help. Thanks!

1

There are 1 best solutions below

2
jared_mamrot On BEST ANSWER

Here is one potential solution using Cindex() from the nftbart package:

# install.packages("nftbart")
library(nftbart)
#> Loading required package: survival
#> Loading required package: nnet

risk_scores <- c(0.4995992, 0.5475576, 0.4896132, 0.5176351, 0.5111408, 0.5035943, 0.4995992, 0.4995992, 0.4935940, 0.4879983, 0.5176351, 0.4966655, 0.4995992, 0.4995920, 0.4896132, 0.5779451)
status <- c(1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
time <- c(455, 210, 1022, 310, 361, 218, 166, 170, 567, 613, 707,  61, 301,  81, 371, 520)

Cindex(risk_scores, time, status)
#> [1] 0.4833333

Created on 2024-03-27 with reprex v2.1.0

Does this method work with your actual data?