plot_roc: Plot ROC curves with confidence intervals.

Description Usage Arguments Details Value Examples

View source: R/roc.R

Description

Plot ROC curves for several different models (or just one) with confidence intervals calculated by pROC::ci.se() and pROC::ci.sp().

Usage

1
2
3
4
5
6
7
8
plot_roc(
  rocdf,
  conf_level = 0.95,
  aes_opts = list(conf_alpha = 0.8, roc_line_size = 1, roc_line_color = "black",
    null_line_size = 1, null_line_color = "blue", null_line_alpha = 0.5),
  quick = TRUE,
  parallel = TRUE
)

Arguments

rocdf

A data frame with columns response and predictor (see pROC::roc(). To plot several models, provide a model column with the model names; one ROC will be calculated and plot per model name.

conf_level

A number in [0, 1]. This is passed as the conf.level argument to pROC::ci.se() and pROC::ci.sp(). Use conf_level = NA to disable plotting of confidence intervals.

aes_opts

A named list of aesthetic options for the plot.

  • conf_alpha: Transparency of the confidence interval lines.

  • roc_line_size: Thickness of the ROC line.

  • roc_line_color: Color of the ROC line.

  • null_line_size: Thickness of the null line.

  • null_line_color: Color of the null line.

  • null_line_alpha: Transparency of the null line

quick

A flag. With quick = FALSE, ROC confidence intervals are calculated with a 2,000-round bootstrap. quick = TRUE will use 100 rounds instead. quick = TRUE is fine for exploration.

parallel

A flag. Calculate the sensitivity and specificity confidence intervals simultaneously? This is a small speedup (<2x).

Details

Inside this function, pROC::roc() is called with direction = "<". The easiest thing is to have rocdf$response be a vector of 0s and 1s and have rocdf$predictor be a vector of probabilities where each probability is the probability of a response of 1. If rocdf$predictor is logical, then these rocdf$predictor is the probability of a response of TRUE.

Value

A ggplot2::ggplot().

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
rocdf1 <- dplyr::tibble( # decent model
  predictor = seq(0.01, 0.99, length.out = 1000),
  response = purrr::rbernoulli(length(predictor), predictor)
)
rocdf2 <- dplyr::tibble( # bad model
  predictor = seq(0.01, 0.99, length.out = 88),
  response = purrr::rbernoulli(length(predictor), 0.5)
)
rocdf12 <- dplyr::bind_rows(
  dplyr::bind_cols(rocdf1, model = "decent"),
  dplyr::bind_cols(rocdf2, model = "bad")
)
plot_roc(rocdf1,
  quick = TRUE, parallel = FALSE,
  aes_opts = list(conf_alpha = 0.3)
)
plot_roc(rocdf2,
  conf_level = NA, quick = TRUE,
  aes_opts = list(roc_line_size = 2, roc_line_color = "red")
)
plot_roc(rocdf12,
  conf_level = NA, quick = TRUE,
  aes_opts = list(null_line_size = 2, null_line_alpha = 1)
)
plot_roc(rocdf12, conf_level = 0.99, quick = TRUE)

mirvie/mirmodels documentation built on Jan. 14, 2022, 11:12 a.m.