Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are R and Python Mann Whitney different?

I am wondering why my answers are so different when doing a mann whitney u test in python and in R. In python:

from scipy.stats import mannwhitneyu
t = [1,2,3]
g = [4,5,6,7,8,9]
mannwhitneyu(t,g)
(0.0, 0.014092901073953692)

In R:

t = c(1,2,3)
g = c(4,5,6,7,8,9)
wilcox.test(t,g, paired = FALSE)

   Wilcoxon rank sum test

data:  t and g
W = 0, p-value = 0.02381
alternative hypothesis: true location shift is not equal to 0

I'm wondering why the python one looks more like a one sided test.

like image 831
user3266890 Avatar asked Mar 18 '23 17:03

user3266890


1 Answers

The scipy version is documented to return a one-sided p-value. (The doc site is down for me at the moment so I can't provide a link, but you can see it if you look at the help for the mannwhitneyu function.) The R function is documented to allow you to specify the sidedness, with two-sided as the default.

like image 96
BrenBarn Avatar answered Mar 21 '23 05:03

BrenBarn