calc_auc: Area under a curve (AUC)

Description Usage Arguments Examples

Description

This function calculates the area under an ROC curve or the area under a precision-recall curve.

Usage

1
calc_auc(x, y)

Arguments

x

the variable plotted on the x-axis of the curve plot, e.g. for a plot with an ROC curve, x-axis is the false positive rate

y

the varialbe plotted on the y-axis of the curve plot, e.g. for a plot with an ROC curve, y-axis is the true positive rate

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
26
27
28
29
30
31
library(tidyverse)
library(broom)
library(tidyroc)

# get `biopsy` dataset from `MASS`
data(biopsy, package = "MASS")

# change column names from `V1`, `V2`, etc. to informative variable names
colnames(biopsy) <-
  c(
    "ID",
    "clump_thickness",
    "uniform_cell_size",
    "uniform_cell_shape",
    "marg_adhesion",
    "epithelial_cell_size",
    "bare_nuclei",
    "bland_chromatin",
    "normal_nucleoli",
    "mitoses",
    "outcome"
  )

# fit a logistic regression model to predict tumour type
glm(outcome ~ clump_thickness + uniform_cell_shape,
  family = binomial,
  data = biopsy
) %>%
  augment() %>% # use broom to add glm output to the #' original data frame
  make_roc(predictor = .fitted, known_class = outcome) %>% # get values to plot an ROC curve
  summarise(auc = calc_auc(x = fpr, y = tpr)) # calculate the area under an ROC curve

dariyasydykova/tidyroc documentation built on May 14, 2019, 11:03 p.m.