First off, I'll state that I'm aware many questions get asked about the c-index. I've searched this site and others, and I haven't found an answer for my situation. I can successfully use validate()
in the rms
package to calculate the Dxy and c-index for my boot-strapped internal validation. Now I need a c-index for my external validation.
I just externally validated my model with an independent data set, and produced the desired plot of actual vs. predicted probabilities using val.surv()
. Unfortunately the abstract I'm submitting cannot have figures, so I feel compelled to report a c-index for the external validation. I have searched this site and the R help archive and haven't found a conclusive answer for how to calculate the c-index on external validation.
I've seen mentions of using rcorr.cens()
in the Hmisc
package, but it seems to me that you can only use it for a single variable's concordance, not an entire model. As of yet I can't find a way to use val.surv()
for calculating a c-index as well. I posted some sample code below, including a test data set to act like an external validation set.
I really appreciate your help in calculating a c-index from an external validation with an independent data set.
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!