R: Receiver Operating Characteristic and Precision-Recall Curves
roc
R Documentation
Receiver Operating Characteristic
and Precision-Recall Curves
Description
Computes the Receiver Operating Characteristic
(ROC) or precision-recall curves from contingencies tables
(confusion matrices) and their associated probabilities, and optionally
plots them.
A data frame representing a contingency tables (confusion matrices) for
a binary classification experiment. The column names should include
TP (for true positive), FN (for false negative),
FP (for false positive), TN (for true negative);
these can be given in any order.
plotit
A logical variable indicating whether or not the ROC curve should be
plotted.
ymax
Upper vertical axis value for plotting precision-recall curves with
prc. The default is max(y), (the maximum value for
precision derived from the contingency table). ymax should be
no larger than 1.
Details
The estimated area may be inaccurate when the sector covered by the
contingency tables is small, and should be used with caution in such cases.
Value
A vector with the following named components:
area
The area under the extended curve (covered by the black solid and
dotted lines).
sector
The estimated area under the sector (below the curve and within the red
lines) covered by the contingency table.
width
The width of the sector (within the red vertical lines)
covered by the contingency table.
As a side-effect, the ROC (roc) or precision-recall curve
(prc) is plotted if plotit = TRUE.
The red vertical lines highlight the sector covered
by the contingency table.
The black lines approximate the curve. They are dotted
beyond the endpoints of the sector, where there is no information
from the contingency table.
The diagonal blue line in the ROC curve indicates the line between (0,0)
and (1,1).
References
J. Davis and M. Goadrich, The relationship between Precision-Recall and
ROC curves, manuscript,
Department of Computer Science, University of Wisconsin.
See Also
contabs
Examples
data(dream4)
network <- 1
nTimePoints <- length(unique(dream4ts10[[network]]$time))
edges1ts10 <- networkBMA( data = dream4ts10[[network]][,-(1:2)],
nTimePoints = nTimePoints, prior.prob = 0.1)
# check for self loops in estimated network
selfN <- any(as.character(edges1ts10[,1]) == as.character(edges1ts10[,2]))
selfN
reference <- dream4gold10[[network]]
# check for self loops in reference (there are none)
selfR <- any(as.character(reference[,1]) == as.character(reference[,2]))
selfR
# restrict reference to edges; first two columns (gene) only
reference <- reference[reference[,3] == 1,1:2]
contingencyTables <- contabs(network = edges1ts10, reference = reference,
size = 100)
roc(contingencyTables)
prc(contingencyTables)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(networkBMA)
Loading required package: BMA
Loading required package: survival
Loading required package: leaps
Loading required package: robustbase
Attaching package: 'robustbase'
The following object is masked from 'package:survival':
heart
Loading required package: inline
Loading required package: rrcov
Scalable Robust Estimators with High Breakdown Point (version 1.3-11)
Loading required package: Rcpp
Attaching package: 'Rcpp'
The following object is masked from 'package:inline':
registerPlugin
Loading required package: RcppArmadillo
Loading required package: RcppEigen
Attaching package: 'RcppEigen'
The following objects are masked from 'package:RcppArmadillo':
fastLm, fastLmPure
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/networkBMA/roc.Rd_%03d_medium.png", width=480, height=480)
> ### Name: roc
> ### Title: Receiver Operating Characteristic and Precision-Recall Curves
> ### Aliases: roc prc
>
> ### ** Examples
>
> data(dream4)
>
> network <- 1
>
> nTimePoints <- length(unique(dream4ts10[[network]]$time))
>
> edges1ts10 <- networkBMA( data = dream4ts10[[network]][,-(1:2)],
+ nTimePoints = nTimePoints, prior.prob = 0.1)
>
> # check for self loops in estimated network
> selfN <- any(as.character(edges1ts10[,1]) == as.character(edges1ts10[,2]))
> selfN
[1] TRUE
>
> reference <- dream4gold10[[network]]
>
> # check for self loops in reference (there are none)
> selfR <- any(as.character(reference[,1]) == as.character(reference[,2]))
> selfR
[1] FALSE
>
> # restrict reference to edges; first two columns (gene) only
> reference <- reference[reference[,3] == 1,1:2]
>
> contingencyTables <- contabs(network = edges1ts10, reference = reference,
+ size = 100)
>
> roc(contingencyTables)
area sector width
0.7003922 0.7003922 0.9529412
> prc(contingencyTables)
area sector width
0.228439 0.214489 1.000000
>
>
>
>
>
> dev.off()
null device
1
>