knitr::opts_chunk$set(
  collapse = F,
  comment = "#>"
)

1 Introduction

The receiver operating characteristic (ROC) and precision recall (PR) is an extensively utilized method for comparing binary classifiers in various areas. However, many real-world problems are designed to multiple classes (e.g., tumor, node, and metastasis staging system of cancer), which require an evaluation strategy to assess multiclass classifiers. This package aims to fill the gap by enabling the calculation of multiclass ROC-AUC and PR-AUC with confidence intervals and the generation of publication-quality figures of multiclass ROC curves and PR curves.

2 Data Preparation

library(multiROC)
data(test_data)
head(test_data)

This example dataset contains two classifiers (m1, m2), and three groups (G1, G2, G3).

3 MultiROC in a nutshell

3.1 multi_roc and multi_pr function

roc_res <- multi_roc(test_data, force_diag=T)
pr_res <- multi_pr(test_data, force_diag=T)

The function multi_roc and multi_pr are core functions for calculating multiclass ROC-AUC and PR-AUC.

Arguments of multi_roc and multi_pr:

Outputs of multi_roc:

Outputs of multi_pr:

3.2 Confidence Intervals

3.2.1 List of AUC results

unlist(roc_res$AUC)

This list shows the following AUC information:

1) AUC of G1 v.s. the rest in the classifier m1; 2) AUC of G2 v.s. the rest in the classifier m1; 3) AUC of G3 v.s. the rest in the classifier m1; 4) AUC of Macro in the classifier m1; 5) AUC of Micro in the classifier m1; 6) AUC of G1 v.s. the rest in the classifier m2; 7) AUC of G2 v.s. the rest in the classifier m2; 8) AUC of G3 v.s. the rest in the classifier m2; 9) AUC of Macro in the classifier m2; 10) AUC of Micro in the classifier m2.

3.2.2 Bootstrap

roc_ci_res <- roc_ci(test_data, conf= 0.95, type='bca', R = 100, index = 4)
roc_ci_res
pr_ci_res <- pr_ci(test_data, conf= 0.95, type='bca', R = 100, index = 4)
pr_ci_res

The function roc_ci and pr_ci are used to calculate confidence intervals of multiclass ROC-AUC and PR-AUC.

Arguments of roc_ci and pr_ci:

Here, we set index = 4 to calculate 95% CI of AUC of Macro in the classifier m1 based on 1000 bootstrap replicates as an example.

roc_auc_with_ci_res <- roc_auc_with_ci(test_data, conf= 0.95, type='bca', R = 100)
roc_auc_with_ci_res
pr_auc_with_ci_res <- pr_auc_with_ci(test_data, conf= 0.95, type='bca', R = 100)
pr_auc_with_ci_res

The function roc_auc_with_ci and pr_auc_with_ci are used to calculate confidence intervals of multiclass ROC-AUC, PR-AUC, and output a dataframe with AUCs, lower CIs, and higher CIs of all methods and groups.

Arguments of roc_auc_with_ci and pr_auc_with_ci:

4 Plots

4.1 change the format of AUC results to a ggplot2 friendly format.

plot_roc_df <- plot_roc_data(roc_res)
plot_pr_df <- plot_pr_data(pr_res)

4.2 Plot

ggplot2::ggplot(plot_roc_df, ggplot2::aes(x = 1-Specificity, y=Sensitivity)) +
  ggplot2::geom_path(ggplot2::aes(color = Group, linetype=Method), size=1.5) +
  ggplot2::geom_segment(ggplot2::aes(x = 0, y = 0, xend = 1, yend = 1), 
                        colour='grey', linetype = 'dotdash') +
  ggplot2::theme_bw() + 
  ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5), 
                 legend.justification=c(1, 0), legend.position=c(.95, .05),
                 legend.title=ggplot2::element_blank(), 
                 legend.background = ggplot2::element_rect(fill=NULL, size=0.5, 
                                                           linetype="solid", colour ="black"))
ggplot2::ggplot(plot_pr_df, ggplot2::aes(x=Recall, y=Precision)) + 
  ggplot2::geom_path(ggplot2::aes(color = Group, linetype=Method), size=1.5) + 
  ggplot2::theme_bw() + 
  ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5), 
                 legend.justification=c(1, 0), legend.position=c(.95, .05),
                 legend.title=ggplot2::element_blank(), 
                 legend.background = ggplot2::element_rect(fill=NULL, size=0.5, 
                                                           linetype="solid", colour ="black"))


elise-is/multiROC documentation built on Nov. 24, 2020, 1:40 a.m.