# load libraries
library(readr)
library(dplyr)
# load test tibble
test_file = system.file("extdata", "test_df.tsv", package = "usefun", mustWork = TRUE)
test_df = readr::read_tsv(test_file, col_types = "di")
# get ROC stats
res = get_roc_stats(df = test_df, pred_col = "score", label_col = "observed")
# Plot ROC with a legend showing the AUC value
plot(x = res$roc_stats$FPR, y = res$roc_stats$TPR,
type = 'l', lwd = 2, col = '#377EB8', main = 'ROC curve',
xlab = 'False Positive Rate (FPR)', ylab = 'True Positive Rate (TPR)')
legend('bottomright', legend = round(res$AUC, digits = 3),
title = 'AUC', col = '#377EB8', pch = 19)
grid()
abline(a = 0, b = 1, col = '#FF726F', lty = 2)
# Get two possible cutoffs
youden_index_df = res$roc_stats %>%
filter(dist_from_chance == max(dist_from_chance))
min_classification_df = res$roc_stats %>%
filter(dist_from_0_1 == min(dist_from_0_1))
Run the code above in your browser using DataLab