roc: Calculate a ROC curve

View source: R/roc.R

rocR Documentation

Calculate a ROC curve

Description

Given a data.frame with a numeric predictor variable and a binary outcome variable this function returns a data.frame that includes all elements of the confusion matrix (true positives, false positives, true negatives, and false negatives) for every unique value of the predictor variable. Additionally, the true positive rate (tpr), false positive rate (fpr), true negative rate (tnr) and false negative rate (fnr) are returned.

Usage

roc(data, x, class, pos_class, neg_class, direction = ">=", silent = FALSE)

Arguments

data

A data.frame or matrix. Will be converted to a data.frame.

x

The name of the numeric predictor variable.

class

The name of the binary outcome variable.

pos_class

The value of 'class' that represents the positive cases.

neg_class

The value of 'class' that represents the negative cases.

direction

(character) One of ">=" or "<=". Specifies if the positive class is associated with higher values of x (default).

silent

If FALSE and the ROC curve contains no positives or negatives, a warning is generated.

Details

To enable classifying all observations as belonging to only one class the predictor values will be augmented by Inf or -Inf. The returned object can be plotted with plot_roc.

This function uses tidyeval to support unquoted arguments. For programming with roc the operator !! can be used to unquote an argument, see the examples.

Value

A data frame with the columns x.sorted, tp, fp, tn, fn, tpr, tnr, fpr, and fnr.

Source

Forked from the ROCR package

See Also

Other main cutpointr functions: add_metric(), boot_ci(), boot_test(), cutpointr(), multi_cutpointr(), predict.cutpointr()

Examples

roc_curve <- roc(data = suicide, x = dsi, class = suicide,
  pos_class = "yes", neg_class = "no", direction = ">=")
roc_curve
plot_roc(roc_curve)
auc(roc_curve)

## Unquoting an argument
myvar <- "dsi"
roc(suicide, x = !!myvar, suicide, pos_class = "yes", neg_class = "no")

cutpointr documentation built on April 14, 2022, 1:06 a.m.