Title: | Generate Useful ROC Curve Charts for Print and Interactive Use |
---|---|
Description: | Most ROC curve plots obscure the cutoff values and inhibit interpretation and comparison of multiple curves. This attempts to address those shortcomings by providing plotting and interactive tools. Functions are provided to generate an interactive ROC curve plot for web use, and print versions. A Shiny application implementing the functions is also included. |
Authors: | Michael C. Sachs [aut, cre], Robert W. Corty [ctb], Luis Crouch [ctb] (Modification to calc_auc) |
Maintainer: | Michael C. Sachs <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.3.2 |
Built: | 2024-11-14 23:27:00 UTC |
Source: | https://github.com/sachsmc/plotROC |
Given a ggplot object with a GeomRoc layer, computes the area under the ROC curve for each group
calc_auc(ggroc)
calc_auc(ggroc)
ggroc |
A ggplot object that contains a GeomRoc layer |
A data frame with the estimated AUCs for each layer, panel and group
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggroc <- ggplot(rocdata, aes(m = M, d = D)) + geom_roc() calc_auc(ggroc) ggroc2 <- ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() calc_auc(ggroc2)
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggroc <- ggplot(rocdata, aes(m = M, d = D)) + geom_roc() calc_auc(ggroc) ggroc2 <- ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() calc_auc(ggroc2)
Deprecated, use geom_roc instead
calculate_multi_roc(data, M_string, D_string)
calculate_multi_roc(data, M_string, D_string)
data |
data frame containing at least 1 marker and the common class labels, coded as 0 and 1 |
M_string |
vector of marker column names |
D_string |
class label column name |
List of data frames containing cutoffs, and estimated true and false positive fractions
Deprecated, use geom_roc instead
calculate_roc(M, D, ci = FALSE, alpha = 0.05)
calculate_roc(M, D, ci = FALSE, alpha = 0.05)
M |
continuous marker values or predictions of class labels |
D |
class labels, must be coded as 0 and 1. If not numeric with 0/1, then plotROC assumes the first level in sort order is healthy status, with a warning. |
ci |
Logical, if true, will calculate exact joint confidence regions for the TPF and FPF |
alpha |
Confidence level, ignored if |
Confidence intervals for TPF and FPF are calculated using the exact
method of Clopper and Pearson (1934) each at the level 1 - sqrt(1 -
alpha)
. Based on result 2.4 from Pepe (2003), the cross-product of these
intervals yields a 1 - alpha
A dataframe containing cutoffs, estimated true and false positive
fractions, and confidence intervals if ci = TRUE
.
Add direct labels to a ROC plot
direct_label( ggroc_p, labels = NULL, label.angle = 45, nudge_x = 0, nudge_y = 0, size = 6, ... )
direct_label( ggroc_p, labels = NULL, label.angle = 45, nudge_x = 0, nudge_y = 0, size = 6, ... )
ggroc_p |
A ggplot object that contains a geom_roc layer |
labels |
vector of labels to add directly to the plot next to the curves. If multiple curves, must be in the same order as the grouping factor. If NULL, attempts to determine labels from the ggroc_p object |
label.angle |
angle of adjustment for the direct labels |
nudge_x , nudge_y
|
Horizontal and vertical adjustment to nudge labels by. These can be scalars or vectors the same length as the number of labels |
size |
Size of labels |
... |
Other arguments passed to annotate |
Takes a ggplot object that contains a GeomRoc layer and returns a string that contains html suitable for creating a standalone interactive ROC curve plot.
export_interactive_roc( ggroc_p, add.cis = TRUE, hide.points = FALSE, prefix = "a", width = 6, height = 6, omit.js = FALSE, style = style_roc(theme = theme_grey()), ... )
export_interactive_roc( ggroc_p, add.cis = TRUE, hide.points = FALSE, prefix = "a", width = 6, height = 6, omit.js = FALSE, style = style_roc(theme = theme_grey()), ... )
ggroc_p |
A ggplot object with a GeomRoc layer and optionally a GeomRocci layer as returned by geom_roc and/or geom_rocci. It can be modified with annotations, themes, etc. |
add.cis |
Logical, if true, removes the current confidence interval layer (if present) and replaces it with a denser layer of confidence regions |
hide.points |
Logical, if true, hides points layer so that points with cutoff values are only visible when hovering. Recommended for plots containing more than 3 curves. |
prefix |
A string to assign to the objects within the svg. Enables unique identification by the javascript code |
width , height
|
Width and height in inches of plot |
omit.js |
Logical. If true, omit inclusion of javascript source in output. Useful for documents with multiple interactive plots |
style |
A call to the function style_roc |
... |
Other arguments passed to geom_rocci when |
If you intend to include more than one of these objects in a single
page, use a different prefix
string for each one. To use this
function in knitr, use the chunk options fig.keep='none'
and
results = 'asis'
, then cat()
the resulting string to the
output. See the vignette for examples. Older browsers (< IE7) are not
supported.
A character object containing the html necessary to plot the ROC curve in a web browser
Display rectangular confidence regions for the empirical ROC curve.
geom_rocci( mapping = NULL, data = NULL, stat = "rocci", ci.at = NULL, sig.level = 0.05, na.rm = TRUE, alpha.box = 0.3, labels = TRUE, labelsize = 3.88, labelround = 1, position = "identity", show.legend = NA, inherit.aes = TRUE, ... ) GeomRocci
geom_rocci( mapping = NULL, data = NULL, stat = "rocci", ci.at = NULL, sig.level = 0.05, na.rm = TRUE, alpha.box = 0.3, labels = TRUE, labelsize = 3.88, labelround = 1, position = "identity", show.legend = NA, inherit.aes = TRUE, ... ) GeomRocci
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Use to override the default connection between
|
ci.at |
Vector of values in the range of the biomarker where confidence regions will be displayed |
sig.level |
Significance level for the confidence regions |
na.rm |
If |
alpha.box |
Alpha level for the confidence regions |
labels |
If TRUE, adds text labels for the cutoffs where the confidence regions are displayed |
labelsize |
Size of cutoff text labels |
labelround |
Integer, number of significant digits to round cutoff labels |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
An object of class GeomRocci
(inherits from Geom
, ggproto
, gg
) of length 6.
geom_rocci
understands the following aesthetics (required aesthetics
are in bold). stat_rocci
automatically maps the estimates to the required aesthetics:
x
The FPF estimate
y
The TPF estimate
xmin
Lower confidence limit for the FPF
xmax
Upper confidence limit for the FPF
ymin
Lower confidence limit for the TPF
ymax
Upper confidence limit for the TPF
alpha
color
fill
linetype
size
See geom_roc
for the empirical ROC curve, style_roc
for
adding guidelines and labels, and direct_label
for adding direct labels to the
curves. Also export_interactive_roc for creating interactive ROC curve plots for use in a web browser.
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(sig.level = .01) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 0) + geom_rocci(ci.at = quantile(rocdata$M, c(.1, .25, .5, .75, .9))) ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(linetype = 1)
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(sig.level = .01) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 0) + geom_rocci(ci.at = quantile(rocdata$M, c(.1, .25, .5, .75, .9))) ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(linetype = 1)
Display the empirical ROC curve. Useful for characterizing the classification accuracy of continuous measurements for predicting binary states
GeomRoc geom_roc( mapping = NULL, data = NULL, stat = "roc", n.cuts = 10, arrow = NULL, lineend = "butt", linejoin = "round", linemitre = 1, linealpha = 1, pointalpha = 1, pointsize = 0.5, labels = TRUE, labelsize = 3.88, labelround = 1, na.rm = TRUE, cutoffs.at = NULL, cutoff.labels = NULL, position = "identity", show.legend = NA, inherit.aes = TRUE, ... )
GeomRoc geom_roc( mapping = NULL, data = NULL, stat = "roc", n.cuts = 10, arrow = NULL, lineend = "butt", linejoin = "round", linemitre = 1, linealpha = 1, pointalpha = 1, pointsize = 0.5, labels = TRUE, labelsize = 3.88, labelround = 1, na.rm = TRUE, cutoffs.at = NULL, cutoff.labels = NULL, position = "identity", show.legend = NA, inherit.aes = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
Use to override the default connection between
|
n.cuts |
Number of cutpoints to display along each curve |
arrow |
Arrow specification, as created by |
lineend |
Line end style (round, butt, square) |
linejoin |
Line join style (round, mitre, bevel) |
linemitre |
Line mitre limit (number greater than 1) |
linealpha |
Alpha level for the lines, alpha.line is deprecated |
pointalpha |
Alpha level for the cutoff points, alpha.point is deprecated |
pointsize |
Size of cutoff points, size.point is deprecated |
labels |
Logical, display cutoff text labels |
labelsize |
Size of cutoff text labels |
labelround |
Integer, number of significant digits to round cutoff labels |
na.rm |
Remove missing values from curve |
cutoffs.at |
Vector of user supplied cutoffs to plot as points. If non-NULL, it will override the values of n.cuts and plot the observed cutoffs closest to the user-supplied ones. |
cutoff.labels |
vector of user-supplied labels for the cutoffs. Must be a character vector of the same length as cutoffs.at. |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
... |
Other arguments passed on to |
An object of class GeomRoc
(inherits from Geom
, ggproto
, gg
) of length 6.
estimate of false positive fraction
estimate of true positive fraction
values of m at which estimates are calculated
geom_roc
understands the following aesthetics (required aesthetics
are in bold):
x
The FPF estimate. This is automatically mapped by stat_roc
y
The TPF estimate. This is automatically mapped by stat_roc
smallest level in sort order is assumed to be 0, with a warning
alpha
color
fill
linetype
size
See geom_rocci
for
displaying rectangular confidence regions for the empirical ROC curve, style_roc
for
adding guidelines and labels, and direct_label
for adding direct labels to the
curves. Also export_interactive_roc for creating interactive ROC curve plots for use in a web browser.
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + facet_wrap(~ Z) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 20) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(cutoffs.at = c(1.5, 1, .5, 0, -.5)) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(labels = FALSE) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(size = 1.25)
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + facet_wrap(~ Z) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 20) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(cutoffs.at = c(1.5, 1, .5, 0, -.5)) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(labels = FALSE) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(size = 1.25)
Reads included JavaScript functions and returns them as a string for pasting into a webpage
getD3()
getD3()
Deprecated, use geom_roc instead
ggroc( rocdata, fpf_string = "FPF", tpf_string = "TPF", c_string = "c", ci = FALSE, label = NULL, label.adj.x = 0, label.adj.y = 0, label.angle = 45, plotmath = FALSE, xlabel = "False positive fraction", ylabel = "True positive fraction" )
ggroc( rocdata, fpf_string = "FPF", tpf_string = "TPF", c_string = "c", ci = FALSE, label = NULL, label.adj.x = 0, label.adj.y = 0, label.angle = 45, plotmath = FALSE, xlabel = "False positive fraction", ylabel = "True positive fraction" )
rocdata |
Data frame containing true and false positive fractions, and cutoff values |
fpf_string |
Column name identifying false positive fraction column |
tpf_string |
Column name identifying true positive fraction column |
c_string |
Column name identifying cutoff values |
ci |
Logical, not supported |
label |
Not supported |
label.adj.x |
Not supported |
label.adj.y |
Not supported |
label.angle |
Not supported |
plotmath |
Not supported |
xlabel |
Defaults to "False positive fraction" |
ylabel |
Defaults to "True positive fraction" |
A ggplot object
Multiple biomarkers measured on the same subjects are often stored as multiple columns in a data frame. This is a convenience function that transforms the data into long format, suitable for use with ggplot and geom_roc
melt_roc(data, d, m, names = NULL)
melt_roc(data, d, m, names = NULL)
data |
Data frame containing disease status and biomarkers stored in columns |
d |
Column containing binary disease status. Can be a column name or index |
m |
Vector of column names or indices identifying biomarkers |
names |
Optional vector of names to assign to the biomarkers. If NULL, names will be taken from the column names |
A data frame in long format with three columns: D = binary disease status, M = biomarker value, and name = biomarker name
D.ex <- rbinom(50, 1, .5) widedata <- data.frame(D = D.ex, M1 = rnorm(50, mean = D.ex, sd = 1), M2 = rnorm(50, mean = D.ex, sd = .5)) longdata <- melt_roc(widedata, "D", c("M1", "M2")) ggplot(longdata, aes(d = D, m = M, color = name)) + geom_roc()
D.ex <- rbinom(50, 1, .5) widedata <- data.frame(D = D.ex, M1 = rnorm(50, mean = D.ex, sd = 1), M2 = rnorm(50, mean = D.ex, sd = .5)) longdata <- melt_roc(widedata, "D", c("M1", "M2")) ggplot(longdata, aes(d = D, m = M, color = name)) + geom_roc()
Given a list of results computed by calculate_roc, plot the curve using ggplot with sensible defaults. Pass the resulting object and data to export_interactive_roc, plot_interactive_roc, or plot_journal_roc.
multi_ggroc( datalist, fpf_string = rep("FPF", length(datalist)), tpf_string = rep("TPF", length(datalist)), c_string = rep("c", length(datalist)), label = NULL, legend = TRUE, label.adj.x = rep(0, length(datalist)), label.adj.y = rep(0, length(datalist)), label.angle = rep(45, length(datalist)), plotmath = FALSE, xlabel = "False positive fraction", ylabel = "True positive fraction" )
multi_ggroc( datalist, fpf_string = rep("FPF", length(datalist)), tpf_string = rep("TPF", length(datalist)), c_string = rep("c", length(datalist)), label = NULL, legend = TRUE, label.adj.x = rep(0, length(datalist)), label.adj.y = rep(0, length(datalist)), label.angle = rep(45, length(datalist)), plotmath = FALSE, xlabel = "False positive fraction", ylabel = "True positive fraction" )
datalist |
List of data frames each containing true and false positive fractions and cutoffs |
fpf_string |
Column names identifying false positive fraction |
tpf_string |
Column names identifying true positive fraction |
c_string |
Column names identifying cutoff values |
label |
Not supported. |
legend |
If true, draws legend |
label.adj.x |
Not supported. |
label.adj.y |
Not supported. |
label.angle |
Not supported. |
plotmath |
Logical. Not supported. |
xlabel |
Defaults to "False positive fraction" |
ylabel |
Defaults to "True positive fraction" |
A ggplot object
Generate a standalone html document displaying an interactive ROC curve
plot_interactive_roc(ggroc, file = NULL, ...)
plot_interactive_roc(ggroc, file = NULL, ...)
ggroc |
An object as returned by ggroc or multi_ggroc. It can be modified with annotations, themes, etc. |
file |
A path to save the result to. If NULL, will save to a temporary directory |
... |
arguments passed to export_interactive_roc |
NULL opens an interactive document in Rstudio or the default web browser
Deprecated, use style_roc instead
plot_journal_roc( ggroc_p, font.size = 3, n.cuts = 20, ci.at = NULL, opacity = 0.3, lty = NULL, color = NULL, lwd = NULL, legend = FALSE )
plot_journal_roc( ggroc_p, font.size = 3, n.cuts = 20, ci.at = NULL, opacity = 0.3, lty = NULL, color = NULL, lwd = NULL, legend = FALSE )
ggroc_p |
An object as returned by ggroc or multi_ggroc. It can be modified with annotations, themes, etc. |
font.size |
Not supported |
n.cuts |
Not supported |
ci.at |
Not supported |
opacity |
Not supported |
lty |
Not supported |
color |
Not supported |
lwd |
Not supported |
legend |
Not supported |
A ggplot object
Generate Useful ROC Curve Charts for Print and Interactive Use. This defines a set of stats and geoms for use with ggplot2. In addition, ggplot objects created with these geoms can be exported and turned into interactive plots for use on the web. The interactive features include hovering to display hidden labels, and clicking to reveal confidence regions.
To get started, see geom_roc, geom_rocci, or the examples below. For transforming data, we also provide the convenience function melt_roc.
The vignette contains some examples, along with explanations of the results. To view, run
vignette("examples", package = "plotROC")
Michael Sachs (@sachsmc)
Useful links:
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + style_roc() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(sig.level = .01) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 0) + geom_rocci(ci.at = quantile(rocdata$M, c(.1, .25, .5, .75, .9))) ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(linetype = 1) rocplot <- ggplot(rocdata, aes(m = M, d = D)) + geom_roc() plot_interactive_roc(rocplot) plot_interactive_roc(rocplot + aes(color = Z)) plot_interactive_roc(rocplot + facet_wrap( ~ Z))
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + style_roc() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci() ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(sig.level = .01) ggplot(rocdata, aes(m = M, d = D)) + geom_roc(n.cuts = 0) + geom_rocci(ci.at = quantile(rocdata$M, c(.1, .25, .5, .75, .9))) ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc() + geom_rocci(linetype = 1) rocplot <- ggplot(rocdata, aes(m = M, d = D)) + geom_roc() plot_interactive_roc(rocplot) plot_interactive_roc(rocplot + aes(color = Z)) plot_interactive_roc(rocplot + facet_wrap( ~ Z))
Key for ROC geom
roc_key(data, params, size)
roc_key(data, params, size)
data |
Data created by stat |
params |
parameters |
size |
Size |
A convenience function to easily start the shiny application. It will open in Rstudio, or in the default web browser.
shiny_plotROC()
shiny_plotROC()
Given a binary outcome d and continuous measurement m, computes the empirical ROC curve for assessing the classification accuracy of m
StatRoc stat_roc( mapping = NULL, data = NULL, geom = "roc", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, max.num.points = 1000, increasing = TRUE, ... )
StatRoc stat_roc( mapping = NULL, data = NULL, geom = "roc", position = "identity", show.legend = NA, inherit.aes = TRUE, na.rm = TRUE, max.num.points = 1000, increasing = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
na.rm |
Remove missing observations |
max.num.points |
maximum number of points to plot |
increasing |
TRUE (default) if M is positively associated with Pr(D = 1), if FALSE, assumes M is negatively associated with Pr(D = 1) |
... |
Other arguments passed on to |
An object of class StatRoc
(inherits from Stat
, ggproto
, gg
) of length 6.
stat_roc
understands the following aesthetics (required aesthetics
are in bold):
m
The continuous biomarker/predictor
d
The binary outcome, if not coded as 0/1, the
smallest level in sort order is assumed to be 0, with a warning
alpha
Controls the label alpha, see also linealpha
and pointalpha
color
linetype
size
Controls the line weight, see also pointsize
and labelsize
estimate of false positive fraction
estimate of true positive fraction
values of m at which estimates are calculated
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + stat_roc()
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + stat_roc()
Confidence intervals for TPF and FPF are calculated using the exact
method of Clopper and Pearson (1934) each at the level 1 - sqrt(1 -
alpha)
. Based on result 2.4 from Pepe (2003), the cross-product of these
intervals yields a 1 - alpha
StatRocci stat_rocci( mapping = NULL, data = NULL, geom = "rocci", position = "identity", show.legend = NA, inherit.aes = TRUE, ci.at = NULL, sig.level = 0.05, na.rm = TRUE, ... )
StatRocci stat_rocci( mapping = NULL, data = NULL, geom = "rocci", position = "identity", show.legend = NA, inherit.aes = TRUE, ci.at = NULL, sig.level = 0.05, na.rm = TRUE, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data, either as a
|
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
ci.at |
Vector of cutoffs at which to display confidence regions. If NULL, will automatically choose 3 evenly spaced points to display the regions |
sig.level |
Significance level for the confidence regions |
na.rm |
Remove missing observations |
... |
Other arguments passed on to |
An object of class StatRocci
(inherits from Stat
, ggproto
, gg
) of length 6.
stat_rocci
understands the following aesthetics (required aesthetics
are in bold):
m
The continuous biomarker/predictor
d
The binary outcome, if not coded as 0/1, the
smallest level in sort order is assumed to be 0, with a warning
alpha
color
fill
linetype
size
estimate of false positive fraction
estimate of true positive fraction
values of m at which estimates are calculated
lower bound of confidence region for FPF
upper bound of confidence region for FPF
lower bound of confidence region for TPF
upper bound of confidence region for TPF
Clopper, C. J., and Egon S. Pearson. "The use of confidence or fiducial limits illustrated in the case of the binomial." Biometrika (1934): 404-413.
Pepe, M.S. "The Statistical Evaluation of Medical Tests for Classification and Prediction." Oxford (2003).
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + stat_rocci() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + stat_rocci(ci.at = quantile(rocdata$M, c(.1, .3, .5, .7, .9)))
D.ex <- rbinom(50, 1, .5) rocdata <- data.frame(D = c(D.ex, D.ex), M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)), Z = c(rep("A", 50), rep("B", 50))) ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + stat_rocci() ggplot(rocdata, aes(m = M, d = D)) + geom_roc() + stat_rocci(ci.at = quantile(rocdata$M, c(.1, .3, .5, .7, .9)))
Adds a diagonal guideline, minor grid lines, and optionally direct labels to ggplot objects containing a geom_roc layer.
style_roc( major.breaks = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1), minor.breaks = c(seq(0, 0.1, by = 0.01), seq(0.9, 1, by = 0.01)), guide = TRUE, xlab = "False positive fraction", ylab = "True positive fraction", theme = theme_bw )
style_roc( major.breaks = c(0, 0.1, 0.25, 0.5, 0.75, 0.9, 1), minor.breaks = c(seq(0, 0.1, by = 0.01), seq(0.9, 1, by = 0.01)), guide = TRUE, xlab = "False positive fraction", ylab = "True positive fraction", theme = theme_bw )
major.breaks |
vector of breakpoints for the major gridlines and axes |
minor.breaks |
vector of breakpoints for the minor gridlines and axes |
guide |
logical, if TRUE draws diagonal guideline |
xlab |
X-axis label |
ylab |
Y-axis label |
theme |
Theme function compatible with ggplot2 |
D.ex <- rbinom(50, 1, .5) fakedata <- data.frame(M1 = rnorm(50, mean = D.ex), D = D.ex) ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc() ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc(xlab = "1 - Specificity") ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc(theme = theme_grey)
D.ex <- rbinom(50, 1, .5) fakedata <- data.frame(M1 = rnorm(50, mean = D.ex), D = D.ex) ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc() ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc(xlab = "1 - Specificity") ggplot(fakedata, aes(m = M1, d = D)) + geom_roc() + style_roc(theme = theme_grey)
Checks for two classes and gives a warning message indicating which level is assumed to be 0/1. Throws an error if more than two levels appear in D.
verify_d(D)
verify_d(D)
D |
Vector that will be checked for 2-class labels |
A vector the same length as D that takes values 0, indicating no disease or 1 indicating disease.
verify_d(c(1, 0, 1)) ## Not run: verify_d(c(TRUE, FALSE, TRUE)) #warning verify_d(c("Dead", "Alive", "Dead")) #warning verify_d(c("Disease", "Healthy", "Missing")) #error ## End(Not run)
verify_d(c(1, 0, 1)) ## Not run: verify_d(c(TRUE, FALSE, TRUE)) #warning verify_d(c("Dead", "Alive", "Dead")) #warning verify_d(c("Disease", "Healthy", "Missing")) #error ## End(Not run)