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$ Jul 13, 2018 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$ Jul 13, 2018 at 14:16
  • $\begingroup$ I am the author of dunn.test, which only does two-sided tests. The problem is that some folks (like Olive Dunn in the article where she introduced the test) conventionally define two-sided p values as $p = P(Z \ge |z|)$ in contrast with others who conventionally define them as $p = P(|Z| \ge |z|)$. The former gives exactly 1/2 the latter, and so rejections are made when $p \le \frac{\alpha}{2}$ for the former, whereas they are made when $p \le \alpha$ for the latter. Both conventions give identical rejection decisions. $\endgroup$
    – Alexis
    Dec 18, 2021 at 19:15

1 Answer 1


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
  • 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$ Jul 14, 2018 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$ Jul 14, 2018 at 13:58
  • $\begingroup$ +1 Sal, see my comment to the original question. Aside: The FSA version is just a "repackaging" of my test. $\endgroup$
    – Alexis
    Dec 18, 2021 at 19:14
  • 1
    $\begingroup$ Hi, @Alexis , in fairness to FSA, the documentation does say, This is largely a wrapper for the dunn.test function in dunn.test. Please see and cite that package.. I do like the table output from that package, and the p-value that's reported. $\endgroup$ Dec 19, 2021 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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