ROC and AUC

Share:

Description

ROC/AUC methods. fast.auc calculates the AUC using a sort operation, instead of summing over pairwise differences in R.
computeRoc computes an ROC curve.
plotRoc plots an ROC curve.
addRoc adds an ROC curve to a plot.
classification.error computes classification error

Usage

1
2
3
4
5
fast.auc (score, outcome, t0 = 0, t1 = 1, reverse.sign.if.nece = TRUE)
computeRoc (score, outcome, reverse.sign.if.nece = TRUE)
plotRoc(x, add = FALSE, type = "l", diag.line=TRUE,...)
addRoc (x,...)
classification.error (score, outcome)

Arguments

score

a vector. Linear combination or score.

outcome

a vector of 0 and 1. Outcome.

t0

a number between 0 and 1 that is the lower boundary of pAUC

t1

a number between 0 and 1 that is the upper boundary of pAUC

reverse.sign.if.nece

a boolean. If TRUE, score is multiplied by -1 if AUC is less than 0.5.

x

a list of two elements: sensitivity and specificity.

diag.line

boolean. If TRUE, a diagonal line is plotted

add

boolean. If TRUE, add to existing plot. If FALSE, create a new plot.

type

line type for lines

...

arguments passed to plot or lines

Details

These functions originally come from Thomas Lumley and Tianxi Cai et al.

Value

computeRoc returns a list of sensitivity and specificity.
plotRoc and addRoc plots ROC curves.

Author(s)

Shuxin Yin
Youyi Fong youyifong@gmail.com
Krisztian Sebestyen

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
n=1e2
score=c(rnorm(n/2,1), rnorm(n/2,0))
outcome=rep(1:0, each=n/2)
plotRoc(computeRoc(score, outcome))


# test, fast.auc2 is a version without all the checking

score=rnorm(1e5)
outcome=rbinom(1e5,1,.5)
system.time(for (i in 1:1e2) fast.auc(score,outcome)) # 4.9 sec
#system.time(for (i in 1:1e2) fast.auc2(score,outcome)) # 3.8 sec