This function integrates AUC using weights
*w(t) = 2*f(t)*S(t)*
as discussed in Heagerty and Zheng, 2005.

1 | ```
IntegrateAUC(AUC, utimes, St, tmax, weight="rescale")
``` |

`AUC` |
Area under ROC curve at utimes |

`utimes` |
Unique event times for subjects |

`St` |
Estimated survival probability at utimes |

`tmax` |
Maximum time length to be considered |

`weight` |
Either of "rescale" or "conditional" |

This function estimates time-dependent concordance measure

*P(M_i>M_j|T_i<t, T_i<tmax, T_j>t)*

as discussed in the
paper from AUC and weights derived from
the survival time distribution. The concordance measure is estimated
under the assumption that smaller of the two event times happened
before time *tmax*. The resulting measure is an weighted sum of
estimated AUC at each unique failure time where weights are
proportional to *2*f(t)*S(t)*, and T is failure time of interest.
If weight="rescale", then the weights are rescaled so that the sum of
the weights is one. If weight="conditional", it is assumed that both
the events happened before *tmax*.

Returns the following item:

`iAUC` |
Integrated AUC using w(t) as above as weights |

Patrick J. Heagerty

Heagerty, P.J., Zheng Y. (2005)
Survival Model Predictive Accuracy and ROC curves
*Biometrics*, **61**, 92 – 105

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 | ```
library(MASS)
data(VA)
survival.time <- VA$stime
survival.status <- VA$status
score <- VA$Karn
cell.type <- factor(VA$cell )
tx <- as.integer( VA$treat==1 )
age <- VA$age
survival.status[VA$stime > 500 ] <- 0
survival.time[VA$stime > 500 ] <- 500
library(survival)
## first find the estimated survival probabilities at unique failure times
surv.prob <- unique(survfit(Surv(survival.time,survival.status)~1)$surv)
fit0 <- coxph( Surv(survival.time,survival.status)
~ score + cell.type + tx + age, na.action=na.omit )
eta <- fit0$linear.predictor
model.score <- eta
utimes <- unique( survival.time[ survival.status == 1 ] )
utimes <- utimes[ order(utimes) ]
## find AUC at unique failure times
AUC <- rep( NA, length(utimes) )
for( j in 1:length(utimes) )
{
out <- CoxWeights( eta, survival.time, survival.status,utimes[j])
AUC[j] <- out$AUC
}
## integrated AUC to get concordance measure
iAUC <- IntegrateAUC( AUC, utimes, surv.prob, tmax=365 )
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.