plot_cutpointr {cutpointr}R Documentation

General purpose plotting function for cutpointr or roc_cutpointr objects

Description

Flexibly plot various metrics against all cutpoints or any other metric. The function can plot any metric based on a cutpointr or roc_cutpointr object. If cutpointr was run with bootstrapping, bootstrapped confidence intervals can be plotted. These represent the quantiles of the distribution of the y-variable grouped by x-variable over all bootstrap repetitions.

Usage

plot_cutpointr(
  x,
  xvar = cutpoint,
  yvar = sum_sens_spec,
  conf_lvl = 0.95,
  aspect_ratio = NULL
)

Arguments

x

A cutpointr or roc_cutpointr object.

xvar

A function, typically cutpoint or a metric function.

yvar

A function, typically a metric function.

conf_lvl

(numeric) If bootstrapping was run and x is a cutpointr object, a confidence interval at the level of conf_lvl can be plotted. To plot no confidence interval set conf_lvl = 0.

aspect_ratio

(numeric) Set to 1 to obtain a quadratic plot, e.g. for plotting a ROC curve.

Details

The arguments to xvar and yvar should be metric functions. Any metric function that is suitable for cutpointr can also be used in plot_cutpointr. Anonymous functions are also allowed. To plot all possible cutpoints, the utility function cutpoint can be used.

The functions for xvar and yvar may accept any or all of the arguments tp, fp, tn, or fn and return a numeric vector, a matrix or a data.frame. For more details on metric functions see vignette("cutpointr").

Note that confidence intervals can only be correctly plotted if the values of xvar are constant across bootstrap samples. For example, confidence intervals for tpr by fpr (a ROC curve) cannot be plotted, as the values of the false positive rate vary per bootstrap sample.

See Also

Other cutpointr plotting functions: plot.cutpointr(), plot_cut_boot(), plot_metric_boot(), plot_metric(), plot_precision_recall(), plot_roc(), plot_sensitivity_specificity(), plot_x()

Examples

set.seed(1)
oc <- cutpointr(suicide, dsi, suicide, boot_runs = 10)

plot_cutpointr(oc, cutpoint, F1_score)

## ROC curve
plot_cutpointr(oc, fpr, tpr, aspect_ratio = 1)

## Custom function
plot_cutpointr(oc, cutpoint, function(tp, tn, fp, fn, ...) tp / fp) +
  ggplot2::ggtitle("Custom metric") + ggplot2::ylab("value")


[Package cutpointr version 1.1.1 Index]