# NOT RUN {
data(aSAH)
# Build a ROC object and compute the AUC
roc(aSAH$outcome, aSAH$s100b)
roc(outcome ~ s100b, aSAH)
# Smooth ROC curve
roc(outcome ~ s100b, aSAH, smooth=TRUE)
# more options, CI and plotting
roc1 <- roc(aSAH$outcome,
aSAH$s100b, percent=TRUE,
# arguments for auc
partial.auc=c(100, 90), partial.auc.correct=TRUE,
partial.auc.focus="sens",
# arguments for ci
ci=TRUE, boot.n=100, ci.alpha=0.9, stratified=FALSE,
# arguments for plot
plot=TRUE, auc.polygon=TRUE, max.auc.polygon=TRUE, grid=TRUE,
print.auc=TRUE, show.thres=TRUE)
# Add to an existing plot. Beware of 'percent' specification!
roc2 <- roc(aSAH$outcome, aSAH$wfns,
plot=TRUE, add=TRUE, percent=roc1$percent)
## Coordinates of the curve ##
coords(roc1, "best", ret=c("threshold", "specificity", "1-npv"))
coords(roc2, "local maximas", ret=c("threshold", "sens", "spec", "ppv", "npv"))
## Confidence intervals ##
# CI of the AUC
ci(roc2)
# }
# NOT RUN {
# CI of the curve
sens.ci <- ci.se(roc1, specificities=seq(0, 100, 5))
plot(sens.ci, type="shape", col="lightblue")
plot(sens.ci, type="bars")
# }
# NOT RUN {
# need to re-add roc2 over the shape
plot(roc2, add=TRUE)
# }
# NOT RUN {
# CI of thresholds
plot(ci.thresholds(roc2))
# }
# NOT RUN {
# In parallel
if (require(doParallel)) {
registerDoParallel(cl <- makeCluster(getOption("mc.cores", 2L)))
# }
# NOT RUN {
ci(roc2, method="bootstrap", parallel=TRUE)
# }
# NOT RUN {
# }
# NOT RUN {
stopCluster(cl)
}
## Comparisons ##
# Test on the whole AUC
roc.test(roc1, roc2, reuse.auc=FALSE)
# }
# NOT RUN {
# Test on a portion of the whole AUC
roc.test(roc1, roc2, reuse.auc=FALSE, partial.auc=c(100, 90),
partial.auc.focus="se", partial.auc.correct=TRUE)
# With modified bootstrap parameters
roc.test(roc1, roc2, reuse.auc=FALSE, partial.auc=c(100, 90),
partial.auc.correct=TRUE, boot.n=1000, boot.stratified=FALSE)
# }
Run the code above in your browser using DataLab