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:

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?


  • $\begingroup$ 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. $\endgroup$ – gung - Reinstate Monica Jul 13 '18 at 14:06
  • 1
    $\begingroup$ @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. $\endgroup$ – 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


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

   ### Comparison of x by group                            
   ### (No adjustment)                                
   ### Col Mean-|
   ### Row Mean |          1
   ### ---------+-----------
   ###        2 |  -1.767766
   ###          |     0.0771
| cite | improve this answer | |
  • 1
    $\begingroup$ 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 $\endgroup$ – Sal Mangiafico Jul 14 '18 at 13:56
  • 1
    $\begingroup$ In general I prefer the dunnTest function in the FSA package. But it appeared to fail with only two groups. $\endgroup$ – Sal Mangiafico Jul 14 '18 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.