Skip to contents

Given a ggplot object with a GeomRoc layer, computes the area under the ROC curve for each group

Usage

calc_auc(ggroc)

Arguments

ggroc

A ggplot object that contains a GeomRoc layer

Value

A data frame with the estimated AUCs for each layer, panel and group

Examples

D.ex <- rbinom(50, 1, .5)
rocdata <- data.frame(D = c(D.ex, D.ex),
                     M = c(rnorm(50, mean = D.ex, sd = .4), rnorm(50, mean = D.ex, sd = 1)),
                     Z = c(rep("A", 50), rep("B", 50)))

ggroc <- ggplot(rocdata, aes(m = M, d = D)) + geom_roc()
calc_auc(ggroc)
#>   PANEL COORD group       AUC
#> 1     1     1    -1 0.8144122
ggroc2 <- ggplot(rocdata, aes(m = M, d = D, color = Z)) + geom_roc()
calc_auc(ggroc2)
#>   PANEL COORD group Z       AUC
#> 1     1     1     1 A 0.9388084
#> 2     1     1     2 B 0.7278583