View source: R/zzz-r4vn-graphs.R View source: R/graphs.R
| groc | R Documentation |
Calculates and draws a receiver operating characteristic curve from a binary outcome and numeric predicted probabilities or scores. No external package is required.
groc(
data = NULL, outcome, pred = NULL, vars = NULL, by = NULL, event = NULL,
diagonal = TRUE, auc = TRUE, digits = 3, curve_lty = 1, curve_lwd = 2.5,
diagonal_color = "gray60", diagonal_lty = 2, diagonal_lwd = 1, xlab = NULL,
ylab = NULL, xtitle = "1 - Specificity", ytitle = "Sensitivity",
title = NULL, subtitle = NULL, note = NULL, color = NULL,
palette = "journal", xline = NULL, yline = NULL, ref_color = "gray40",
ref_lty = 2, ref_lwd = 1, theme = "journal", size = 11, combine = FALSE,
ncol = NULL, file = NULL, width = 6, height = 6, dpi = 300, show = TRUE,
bg = "white", vline = NULL, hline = NULL
)
data |
A data frame. |
outcome |
Binary outcome variable. |
pred |
Numeric predicted probability or score; larger values must indicate a greater probability of the event. |
vars |
Optional |
by |
Optional grouping variable or hierarchical |
event |
Event value. By default, the second factor level or the larger numeric value is used. |
diagonal |
Show the no-discrimination diagonal. |
auc |
Show the area under the curve. |
digits |
Number of AUC digits. |
curve_lty, curve_lwd |
ROC-curve line type and width. |
diagonal_color, diagonal_lty, diagonal_lwd |
Colour, line type, and width of the no-discrimination diagonal. |
xlab, ylab |
Optional tick labels. |
xtitle, ytitle |
Axis titles. |
title, subtitle, note, color, palette, theme, size, combine, ncol, file, width, height, dpi, show, bg |
See |
xline, yline |
Optional numeric reference lines on the x and y axes. |
ref_color, ref_lty, ref_lwd |
Color, line type, and width for reference lines. |
vline, hline |
Deprecated aliases for |
Draws ROC curves for one or several predictor/score variables. by can create
ROC analyses within hierarchical strata.
An object of class r4vn_graph; its data component contains thresholds, sensitivity, and specificity, and its auc attribute contains the AUC.
d <- data.frame(y = c(0, 0, 1, 1, 1), p = c(.10, .35, .40, .75, .90))
groc(d, outcome = y, pred = p, event = 1)
# Extended usage examples
d <- data.frame(
outcome = factor(c("No", "No", "No", "Yes", "Yes", "Yes", "Yes")),
probability = c(.05, .20, .35, .40, .65, .80, .95)
)
# ROC curve with explicit event
roc1 <- groc(d, outcome, probability, event = "Yes", show = FALSE)
attr(roc1$data, "auc")
# Hide the diagonal or AUC annotation and customize labels
groc(d, outcome, probability, event = "Yes",
diagonal = FALSE, auc = FALSE,
xtitle = "False-positive rate", ytitle = "True-positive rate",
show = FALSE)
# Numeric binary outcome; the larger value is the default event
d2 <- data.frame(y = c(0, 0, 1, 1, 1), score = c(.10, .35, .40, .75, .90))
groc(d2, y, score, show = FALSE)
# Export the ROC curve
groc(d, outcome, probability, event = "Yes",
file = tempfile(fileext = ".pdf"), show = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.