Description Usage Arguments Examples
This function calculates true positive rate and false positive rate to plot an ROC curve.
1 |
data |
data-frame that contains fitted values and known outcomes |
predictor |
column in 'data' that contains fitted values |
known_class |
column in 'data' that contains true or actual classification |
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 32 | 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
ggplot(aes(x = fpr, y = tpr)) + # plot false positive rate against true positive rate
geom_line()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.