R语言中五种计算C-index的方法

在生存分析中,描述一个模型的区分能力常常用Cox回归中的C-index来评价。R包中计算C-index的函数有很多,但计算出的值有着细微的差别。下面给出五个函数来计算C-index。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
train_info <- read.csv("./train_info.csv")


# 方法1:利用Hmisc包中的rcorr.cens函数
library(survival)
library(Hmisc)
method1 <- rcorr.cens(train_info$risk_img, Surv(train_info$os, train_info$status))
cat(method1[1], "95%CI:", method1[1]-method1[3]/2*1.96, method1[1]+method1[3]/2*1.96)


# 方法2:利用survival包中的coxph函数
library(survival)
method2 <- summary(coxph(Surv(os, status) ~ risk_img, data = train_info))$concordance
cat(method2[1], "95%CI:", method2[1]-method2[2]*1.96, method2[1]+method2[2]*1.96)


# 方法3:利用survival包中的survConcordance函数
library(survival)
fit <- coxph(Surv(os, status) ~ risk_img, data = train_info)
method3 <- survConcordance(Surv(train_info$os, train_info$status) ~ predict(fit, train_info))
cat(method3$concordance, "95%CI:", method3$concordance-method3$std.err*1.96, method3$concordance+method3$std.err*1.96)

# 方法4:利用survcomp包中的concordance.index函数
library(survcomp)
fit <- coxph(Surv(os, status) ~ risk_img, data = train_info)
cindex <- concordance.index(predict(fit), surv.time = train_info$os, surv.event = train_info$status, method = "noether")
cat(cindex$c.index, "95%CI:", cindex$lower, cindex$upper)


# 方法5:利用rms包中的cph函数和validate函数,可提供un-adjusted CI和bias adjusted CI
library(rms)
cindex.boot <- function(fit.cph) {
set.seed(123)
validate <- rms::validate(fit.cph, dxy = TRUE, B = 1000)
cindex <- (validate["Dxy", c("index.orig","training","test","optimism","index.corrected")])/2 + 0.5
n <- validate["Dxy", c("n")]
res <- rbind(validate, C_index = c(cindex, n))
res["C_index","optimism"] <- res["C_index","optimism"] - 0.5
res
}
cindex.boot(cph(Surv(os, status) ~ risk_img, data = train_info, x = TRUE, y = TRUE, surv = TRUE))