首先,我要声明我知道有很多关于 c-index 的问题。我已经搜索了这个网站和其他网站,但我还没有找到适合我情况的答案。我可以成功地validate()在rms包中使用来计算我的引导内部验证的 Dxy 和 c-index。现在我需要一个 c-index 来进行外部验证。
我刚刚使用独立数据集从外部验证了我的模型,并使用val.surv(). 不幸的是,我提交的摘要没有数字,所以我不得不报告一个 c-index 以进行外部验证。我已经搜索了这个站点和 R 帮助档案,但还没有找到关于如何计算外部验证的 c-index 的结论性答案。
rcorr.cens()我已经看到在包中提到使用Hmisc,但在我看来,您只能将它用于单个变量的一致性,而不是整个模型。到目前为止,我还找不到val.surv()用于计算 c-index 的方法。我在下面发布了一些示例代码,包括一个类似于外部验证集的测试数据集。
我非常感谢您在使用独立数据集从外部验证计算 c-index 方面的帮助。
library(rms)
library(Hmisc)
data(veteran)
##Create a Cox PH model for the training data.
survmod=with(veteran,Surv(time,status))
cox.mod=cph(survmod~celltype+karno,data=veteran,x=T,y=T,surv=TRUE,time.inc=5*365)
##Here is the test data set that is the external "independent" data.
test_dat=data.frame(trt=replicate(500,NA), celltype=replicate(500,NA), time=replicate(500,NA), status=replicate(500,NA), karno=replicate(500,NA), diagtime=replicate(500,NA), age=replicate(500,NA), prior=replicate(500,NA))
for(i in seq(8)){
test_dat[,i]=sample(veteran[,i],500,replace=T)
}
##Validate the model with the test data
test_surv=with(test_dat,Surv(time,status))
validated=val.surv(cox.mod,newdata=test_dat,S=test_surv)
##Now what I need is to take the external validation and compute the
#c-index. This is where I'm stuck.
#I've seen people mention `rcorr.cens()`, but I can't figure out a way to use
#`rcorr.cens()` with a Cox model of several variables. I appreciate your help!