Recently I learned about the relationship between Area Under (ROC) Curve and $U$ statistic of the Wilcoxon-Mann-Whitney test. It is supposed to follow the following rule (got it from this nice post on quora: https://www.quora.com/How-is-statistical-significance-determined-for-ROC-curves-and-AUC-values):
$$AUC = \frac{U}{n_1n_2}$$
It looks convincing, but I made some checks on real data in R
and I found that, indeed, there is a functional relationship between $U$ and $AUC$, but it has slightly different form:
$$AUC = 1 - \frac{U}{n_1n_2}$$
Unfortunately I cannot share the real data I used, but here is a simple simulation that proves the point:
library(PredictABEL)
set.seed(303)
x1 <- rnorm(40, 20, 4)
x2 <- rnorm(50, 30, 10)
y <- c(rep("a", 40), rep("b", 50))
df <- data.frame(x=c(x1, x2), y=y)
mod <- glm(y ~ x, data=df, family=binomial)
plotROC(df, 2, mod$fitted.values) # AUC = 0.81
auc <- 0.81
utest <- wilcox.test(x ~ y, data=df)
utest$statistic / prod(table(df$y)) # = 0.19
1 - utest$statistic / prod(table(df$y)) # = 0.81 = AUC
So, as you see I am a bit confused. I am pretty sure that this whole confusion is only due to the fact that I am overlooking something important, but that's why I will be really thankful if someone could shed some light on it for me.
EDIT: So the question is which of the two formulas is correct? Every source I check claims that the first one but the data I checked suggest that the second one.