[R] Equivalence of Mann-Whitney test and Kruskal-Wallis test with k=2

6 views
Skip to first unread message

Thomas Farrar

unread,
Sep 7, 2009, 5:00:46 PM9/7/09
to r-h...@r-project.org
Hi all,

The Kruskal-Wallis test is a generalization of the two-sample Mann-Whitney
test to *k* samples. That being the case, the Kruskal-Wallis test with *k*=2
should give an identical p-value to the Mann-Whitney test, should it not?

x1<-c(1:5)
x2<-c(6,8,9,11)
a<-wilcox.test(x1,x2,paired=FALSE)
b<-kruskal.test(list(x1,x2),paired=FALSE)
a$p.value
[1] 0.01587302
b$p.value
[1] 0.01430588

The p-values are slightly different (note that there are no ties in the
data, so computed p-values should be exact).

Can anyone explain the discrepancy? It's been awhile since I studied
nonparametric stats and this one has me scratching my head.

Many thanks!
Tom

[[alternative HTML version deleted]]

______________________________________________
R-h...@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

David Scott

unread,
Sep 8, 2009, 1:01:44 AM9/8/09
to Thomas Farrar, r-h...@r-project.org
Thomas Farrar wrote:
> Hi all,
>
> The Kruskal-Wallis test is a generalization of the two-sample Mann-Whitney
> test to *k* samples. That being the case, the Kruskal-Wallis test with *k*=2
> should give an identical p-value to the Mann-Whitney test, should it not?
>
> x1<-c(1:5)
> x2<-c(6,8,9,11)
> a<-wilcox.test(x1,x2,paired=FALSE)
> b<-kruskal.test(list(x1,x2),paired=FALSE)
> a$p.value
> [1] 0.01587302
> b$p.value
> [1] 0.01430588
>
> The p-values are slightly different (note that there are no ties in the
> data, so computed p-values should be exact).
>
> Can anyone explain the discrepancy? It's been awhile since I studied
> nonparametric stats and this one has me scratching my head.
>
> Many thanks!
> Tom
>

The continuity correction? It is true by default for wilcox.test and is
not apparent in the help for kruskal.test.

David Scott

--
_________________________________________________________________
David Scott Department of Statistics
The University of Auckland, PB 92019
Auckland 1142, NEW ZEALAND
Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055
Email: d.s...@auckland.ac.nz, Fax: +64 9 373 7018

Director of Consulting, Department of Statistics

Meyners, Michael, LAUSANNE, AppliedMathematics

unread,
Sep 8, 2009, 2:20:13 AM9/8/09
to David Scott, Thomas Farrar, r-h...@r-project.org
See the respective help files. The continuity correction only affects
the normal approximation in wilcox.test. With this small samples sizes,
the default evaluation is exact, so it doesn't change anything. In
contrast, kruskal.test is incapable to compute exact values but always
uses the chi-square approximation. So the discrepancy is between exact
test and approximation (guess you'd be better off with the former).

If you get the urge to reproduce the p value from kruskal.test using
wilcox.test, and maybe to better understand what's happening, try

a <- wilcox.test(x1, x2, paired=FALSE, exact=FALSE, correct=FALSE)

(and yes, now with exact=FALSE, the continuity correction makes a
difference).

HTH, Michael

Thomas Farrar

unread,
Sep 8, 2009, 2:41:32 AM9/8/09
to Meyners, Michael, LAUSANNE, AppliedMathematics, r-h...@r-project.org
OK, I get it now. Thank you very much!

Cheers,
Tom

[[alternative HTML version deleted]]

Reply all
Reply to author
Forward
0 new messages