cls <- c('P', 'P', 'N', 'P', 'P', 'P', 'N', 'N', 'P', 'N', 'P',
'N', 'P', 'N', 'N', 'N', 'P', 'N', 'P', 'N')
score <- c(0.9, 0.8, 0.7, 0.6, 0.55, 0.51, 0.49, 0.43, 0.42, 0.39, 0.33,
0.31, 0.23, 0.22, 0.19, 0.15, 0.12, 0.11, 0.04, 0.01)
pos <- score[cls == 'P']
neg <- score[cls == 'N']
n <- 50000
out <- logical()
for (i in 1:n) {
p_samp <- sample(pos,1)
n_samp <- sample(neg,1)
out[i] <- p_samp > n_samp
}
mean(out)
## [1] 0.67692
pROC::auc(cls, score)
## Setting levels: control = N, case = P
## Setting direction: controls < cases
## Area under the curve: 0.68