| 1 |
old_cindex=function(yhat,y,status,w=rep(1,length(y))){ |
| 2 |
# Rob's implementation of C-index |
| 3 |
#note: this function gives identical results to the summary function from coxph, and the concordance.index function in survcomp. |
| 4 |
# (with their default settings), and no ties in yhat. Works with ties in y. But does not agree with latter when yhat has ties. There are conflicting definitions for c-index in this case |
| 5 |
# |
| 6 |
#formula used is |
| 7 |
# Concordance = (#all concordant pairs + #tied pairs/2)/(#total pairs including ties). |
| 8 |
# with w, weights used are ave wts for each pair |
| 9 |
time.computeC.start <- Sys.time() |
| 10 |
|
| 11 |
risksets=which(status==1) |
| 12 |
w=length(w)*w/sum(w) |
| 13 |
fun=function(riskset,y,yhat,w){ |
| 14 |
total=concordant=0 |
| 15 |
i=riskset |
| 16 |
rest=which(y>y[i]) |
| 17 |
if(length(rest)>0){ |
| 18 |
ww=w[rest]*w[i] |
| 19 |
total=sum(ww) |
| 20 |
concordant = 1.0*sum(ww*(yhat[rest]<yhat[i]))+0.5*sum(ww*(yhat[rest]==yhat[i])) |
| 21 |
} |
| 22 |
return(c(concordant,total)) |
| 23 |
} |
| 24 |
out=sapply(risksets,fun,y,yhat,w) |
| 25 |
cindex=sum(out[1,])/sum(out[2,]) |
| 26 |
|
| 27 |
return(cindex) |
| 28 |
} |