# import the observed data
data(dataDIVAT3)
# A subgroup analysis to reduce the time needed for this example
dataDIVAT3 <- dataDIVAT3[1:400,]
# import the expected mortality rates
data(fr.ratetable)
# the values of recipient age used for computing the sensibilities and
# specificities (choose more values in practice)
age.cut <- quantile(dataDIVAT3$ageR, probs=seq(0.1, 0.9, by=0.1))
# recoding of the variables for matching with the ratetable
dataDIVAT3$sex <- "male"
dataDIVAT3$sex[dataDIVAT3$sexeR==0] <- "female"
dataDIVAT3$year <- as.numeric(as.Date(paste0(dataDIVAT3$year.tx, "-01-01")) - as.Date("1960-01-01"))
dataDIVAT3$age <- dataDIVAT3$ageR*365
# the ROC curve (without correction by the knn estimator) to
# reduce the time for computing this example. In practice, the
# correction should by used in case of non-montone results.
roc1 <- roc.net(times=dataDIVAT3$death.time,
failures=dataDIVAT3$death, variable=dataDIVAT3$ageR,
p.age=dataDIVAT3$age, p.sex=dataDIVAT3$sex, p.year=dataDIVAT3$year,
rate.table=fr.ratetable, pro.time=3000, cut.off=age.cut, knn=FALSE)
# the sensibilities and specificities associated with the cut off values
roc1$table
# the traditional ROC graph
plot(roc1, col=2, pch=2, lty=2, type="b", xlab="1-specificity", ylab="sensibility")
legend("bottomright", paste("Without knn, (AUC=",
round(roc1$auc, 2), ")", sep=""),lty=1, lwd=2, col=2)
Run the code above in your browser using DataLab