# Is dunn.test for two samples equivalent to wilcox.test?

I know that dunn.test is generally used as a post hoc after Kruskall Wallis to see which groups are different, but to generalize the function I am writing, I was wondering if when only using two groups, under what conditions is the p value from dunn.test equivalent to that of wilcox.test?

For example, if I do:

library(dunn.test)
a = rnorm(n=500, m=1.1, sd=1)
b = rnorm(n=500, m=1, sd=1)


And do dunn.test(list(a, b))\$P, I get exactly half the result of wilcox.test(a, b), as dunn.test seems to be doing a one sided test by default. That is easy to fix.

However, when I do:

c = c(0.026448555266779, 0.024129847627784, 0.027900932579116, 0.025760587066198)

d = c(0.029862915965958, 0.028563420475972, 0.026703358304031)


Then the p-value of dunn.test is 0.03 (one sided) and wilcox.test is 0.11 (two sided). Is this to be expected? Under what conditions?

Thanks!

• This seems to be about a couple of specific functions in R (& is borderline on-topic, IMO); you should at least list the packages you are using. – gung - Reinstate Monica Jul 13 '18 at 14:06
• @gung Sounds good, will do. I just used the R examples as a way to reproduce my results, but any insight from a statistical point of view as to why the answers are theoretically different is what I am looking for. – Jack Arnestad Jul 13 '18 at 14:16

They will be the same if you make some adjustments to the options in the functions.

For wilcox.test, you can disable the exact calculation of the p-value, and the continuity correction.

For dunn.test, you can choose altp = TRUE to change the output to be what we think of as the full two-sided p-value.

C = c(0.026448555266779, 0.024129847627784, 0.027900932579116, 0.025760587066198)

D = c(0.029862915965958, 0.028563420475972, 0.026703358304031)

wilcox.test(C,D, correct=FALSE, exact=FALSE)

### Wilcoxon rank sum test
###
### W = 1, p-value = 0.0771

library(dunn.test)

dunn.test(list(C,D), altp=TRUE)

### Comparison of x by group

• Apparently, the dunn.test function reports by default what looks like a one-sided p-value because that's how the original test was formulated, with the decision rule: Reject Ho if p <= alpha/2 – Sal Mangiafico Jul 14 '18 at 13:56
• In general I prefer the dunnTest function in the FSA package. But it appeared to fail with only two groups. – Sal Mangiafico Jul 14 '18 at 13:58