Guide for use auc function

Simulated data

mu_true <- c(0, 1)
sigma_true <- c(1, 1)
n1 <- 250
n2 <- 250
X1 <- rnorm(n1, mu_true[1], sigma_true[1])
X2 <- rnorm(n2, mu_true[2], sigma_true[2])

Compute AUC

auc(x = X1, y = X2)
#> AUC estimate:
#> [1] 0.748144
#> 
#> 95% Confidence interval:
#> [1] 0.7040046 0.7891054
#> 
#> p-value (greater): 2.11631e-24
data_test <- data.frame(biom = c(X1, X2), diag = rep(c("1", "2"), c(n1, n2)))
auc(formula = biom ~ diag, data = data_test)
#> AUC estimate:
#> [1] 0.748144
#> 
#> 95% Confidence interval:
#> [1] 0.7040046 0.7891054
#> 
#> p-value (greater): 2.11631e-24
auc(formula = biom ~ diag, data = data_test, ci_level = 0.9)
#> AUC estimate:
#> [1] 0.748144
#> 
#> 90% Confidence interval:
#> [1] 0.7113054 0.7827500
#> 
#> p-value (greater): 2.11631e-24
auc(formula = biom ~ diag, data = data_test, diag_levels = c("2", "1"))
#> AUC estimate:
#> [1] 0.251856
#> 
#> 95% Confidence interval:
#> [1] 0.2116358 0.2951347
#> 
#> p-value (greater): 1
out_test <- auc(formula = biom ~ diag, data = data_test)
print(out_test)
#> AUC estimate:
#> [1] 0.748144
#> 
#> 95% Confidence interval:
#> [1] 0.7040046 0.7891054
#> 
#> p-value (greater): 2.11631e-24

Plot

auc(formula = biom ~ diag, data = data_test, plot = TRUE)

#> AUC estimate:
#> [1] 0.748144
#> 
#> 95% Confidence interval:
#> [1] 0.7040046 0.7891054
#> 
#> p-value (greater): 2.11631e-24
out_roc <- ROC_emp_curve(x = X1, y = X2, plot = FALSE)
plot(out_roc) +
    geom_confidence_region(out_roc, cpt = 0.5) +
    geom_operating_point(out_roc, cpt = 0.5)

out_roc_2 <- ROC_emp_curve(formula = biom ~ diag, data = data_test, 
                           plot = FALSE)
p1 <- plot(out_roc_2)
p1

Adding the confidence region for sensitivity and specificity at fixed threshold \(t = 0.5\).

p1 + geom_confidence_region(out_roc_2, cpt = 0.5) +
  geom_operating_point(out_roc_2, cpt = 0.5) 

With optimal threshold

out_thresh <- threshold2(x = X1, y = X2, method = "YI", kernel_type = "gauss", 
                         bwd_type = "AZZ", plot = FALSE)
p1 + geom_confidence_region(out_thresh, cpt_type = "optimal") +
  geom_operating_point(out_thresh, cpt_type = "optimal") 

Monte Carlo simulation

Both bootstrap calibrations below use the signed square root of the adjusted EL statistic to test \(H_0: \mathrm{AUC} = 1/2\) against \(H_1: \mathrm{AUC} > 1/2\). Run the following simulation chunks interactively to reproduce the 5,000 replicates. Each dataset has 30 independent standard normal observations per class, so the null value is \(1/2\). The rejection proportions at all three nominal levels use the same p-values.

Default method

set.seed(34)
auc_null_data <- replicate(5000L, matrix(rnorm(60L), ncol = 2L),
                           simplify = FALSE)
alpha_levels <- c(0.10, 0.05, 0.01)
out_auc_MC <- lapply(seq_along(auc_null_data), function(i) {
  null_sample <- auc_null_data[[i]]
  out_auc_temp <- auc(x = null_sample[, 1], y = null_sample[, 2], auc0 = 0.5,
                      alternative = "greater", B = 500,
                      seed = length(auc_null_data) + i)
  r_mean <- 1/mean(out_auc_temp$r.bts)
  ll_val_mean <- r_mean * out_auc_temp$ll.value
  ll_val_med <- out_auc_temp$ll.value * out_auc_temp$r.adj
  signed_root_mean <- sign(out_auc_temp$estimate - 1/2) * sqrt(max(0, ll_val_mean))
  p_val_mean <- pnorm(signed_root_mean, lower.tail = FALSE)
  p_val_med <- out_auc_temp$p.value
  return(list(ll_val_mean = ll_val_mean, ll_val_med = ll_val_med, 
              p_val_mean = p_val_mean, p_val_med = p_val_med))
})
p_val_auc_mean_MC <- vapply(out_auc_MC, `[[`, numeric(1), "p_val_mean")
hist(p_val_auc_mean_MC)
p_val_auc_med_MC <- vapply(out_auc_MC, `[[`, numeric(1), "p_val_med")
hist(p_val_auc_med_MC)
sapply(alpha_levels, function(x) mean(p_val_auc_mean_MC <= x))
sapply(alpha_levels, function(x) mean(p_val_auc_med_MC <= x))