Code covered by the BSD License

### Highlights from Mann-Whitney-Wilcoxon test

5.0

5.0 | 4 ratings Rate this file 55 Downloads (last 30 days) File Size: 3.05 KB File ID: #25830

# Mann-Whitney-Wilcoxon test

13 Nov 2009 (Updated 23 Dec 2009)

Mann-Whitney-Wilcoxon non parametric test for two unpaired groups.

File Information
Description

This file executes the non parametric Mann-Whitney-Wilcoxon test to evaluate the difference between unpaired samples. If the number of combinations is less than 20000, the algorithm calculate the exact ranks distribution; else it uses a normal distribution approximation. The result is not different from
RANKSUM MatLab function, but there are more output informations. There is an alternative formulation of this test that yields a statistic commonly denoted by U. Also the U statistic is computed.

Syntax: STATS=MWWTEST(X1,X2)

Inputs:
X1 and X2 - data vectors.
Outputs:
- T and U values and p-value when exact ranks distribution is used.
- T and U values, mean, standard deviation, Z value, and p-value when normal distribution is used.
If STATS nargout was specified the results will be stored in the STATS struct.

Example:

X1=[181 183 170 173 174 179 172 175 178 176 158 179 180 172 177];

X2=[168 165 163 175 176 166 163 174 175 173 179 180 176 167 176];

Calling on Matlab the function: mwwtest(X1,X2)

MANN-WHITNEY-WILCOXON TEST
--------------------------------------------------------------------------------
Sample size is good enough to use the normal distribution approximation

T U mT sT zT p-value (1-tailed)
--------------------------------------------------------------------------------
270.0000 150.0000 232.5000 24.1071 1.5348 0.0624
--------------------------------------------------------------------------------

You can visit my homepage http://home.tele2.it/cardillo
My profile on XING http://www.xing.com/go/invita/13675097

Required Products Statistics Toolbox
MATLAB release MATLAB 7.6 (R2008a)
14 Mar 2013

Thank you for your quick response.

Your roc function is indeed very good.

For those who would just want a quick measure of effect size, it's easy to perform the empirical AUC from Giuseppe Cardillo's function by adding:
STATS.auc = U / (L(1)*L(2));

http://www.mathworks.com/matlabcentral/fileexchange/30424-colauc

13 Mar 2013

The results are exactly equal: ranksum gives a 2-tailed p-value and mwwtest gives a 1-tailed p-value. If you need a 2-tailed p-value simply multiply 1-tailed p-value by 2 (or, viceversa, divide 2-tailed p-value by 2 if you need 1-tailed p-value).
For Area Under The Curve, please, look at roc.m function that I wrote.

13 Mar 2013

Thank you very much for this useful function.

Is it normal that the p-values it makes are different from those obtained with matlab's ranksum function:
[p h stats] = ranksum(1:100,11:110)
p: 0.0203

stats = mwwtest(1:100,11:110)
stats.p: 0.0102

If so, which one shall we report?

As an addup, I think it would be great to add an output of the effect size using the area under the curve, as well as the confidence interval.

08 Jul 2012

1) if you have to compare more than 2 groups mwwtest is not the test for you...you should use the Kruskal-Wallis test. Or if you have "repeated measures" of the same group in different moments you should use the Friedman's test.

2) the concept of the mwwtest is that if the medians are equals the ranks will distribute equally in both groups and they will have a mean equal to n1*n2/2 (and so you can use Z-score...). The acceptance is the same of the Student's t-test because T (or U) is asintotically normally distributed. The magnitude of T is not the only parameter....if you two very large samples sizes also mean(T) will be very large...

08 Jul 2012

Thanks Giuseppe for your reply. Didn't know there were different computational methods.

About testing medians; of course I know how to use the median command ;). My research is into finance and I test whether activity of specific type of traders is larger in one period compared the other. I use the Mann-Whitney test in addition to a one-tailed independent sample T-test, because some samples violate the normal distribution severely.

Now I corrected all significant test results, which were in the wrong tail (according to the calculated medians) and thus the null hypothesis holds. In contrast, the T-test is symmetric and concludes on the direction of the result.

What then is the acceptance area of the null hypothesis w.r.t. the MWWtest? I guess it is around n1*n2/2? What if the U-statistic is much larger?

08 Jul 2012

There are two way to compute T: I setup that described by Stanton Glantz in "Primer of biostatistics". U is related to T by a subtraction factor. Z-score is the same because it is (T-mean(T))/std(T): if you use the other computational method, mean(T) and std(T) change of course. This means that both methods are equivalent.

To reply to your question I have to put off a basically error that everybody do. The question median(1)>median(2) have to be asked BEFORE performing test, during experimental design project. An example: you discover a new diuretic drug. You want to demonstrate that group 1 treated by drug has a median value or urine (mL/24h) higher than group 2 treated by placebo. So you ask to mwwtest if median(1)>median(2). Of course you could decide to treat group 2 by drug: the result of mwwtest will be the same.
In many situations, you can't know BEFORE doing test which median should be greater: if you treat group 1 with drug 1 and group 2 with drug 2 you should not hypothesize which drug will be more effective. So you will ask to mwwtest: are median(1) and median(2) different? In this case you will perform a 2-tailed test and so you have to multiply by 2 the result of mwwtest.

Anyway, don't tell me that you don't know how to ask matlab to compute medians....

07 Jul 2012

Test results (both U and T) are different from the results produced by SPSS. However, the Z-score is the same.

In addition, I have a question in case you would like to use the MWW test to test whether the median in group 1 is larger than in group 2 (1-tailed). How can you conclude from the test results which group has the largest median?

18 May 2012

if you like it...
I could decide to set another alpha value for my test (i.e. 0.01) and so your code will give a wrong answare...

18 May 2012

Thank you very much for this work.
I needed an exact answer to the hypothesis so added the following code at the end of yours:

if p<0.05
STATS.H=1; %reject H0
else
STATS.H=0; %fail to reject H0
end

25 Apr 2012
14 Apr 2011

A) i'm trying to use your suggested matlab code; mwwtest(x1,x2). But my 2010a matlab version doesn't recognize this code. How is this possible?
R) I use the same version of MatLab (even if I use the Linux version) and mwwtest properly works. Please, check if your data are correct (see help).

A) Or is it possible that mwwtest code was deleted since the result is equivalent to ranksum(x1,x2) code?
B) If you are writing this comment, it means that mwwtest wasn't deleted. A question: did you download mwwtest from this page before using it?

A) If that is the case, can i replace mwwtest with ranksum?
R) You can use ranksum because, as I wrote in Description, the results are the same.

A)What is the difference between Mann-whitney u test and wilcoxon ranksum test?
R) There is no difference: they are two sides of the same coin. Infact, mwwtest compute both T and U.

A) My advisor is convinced that Mann-whitney tests the difference btw mean while ranksum tests difference of median or distribution rank.
R) Your advisor is wrong. Non parametric tests test differences between medians while parametric tests between means.

A)My final question is if i change to perform ranksum code instead of your suggested mwwtest, ranksum doesn't support 1-tailed test. Is this true? How can I test 1-tailed of ranksum or mwwtest in matlab.
R)Ranksum gives you a 2-tailed p. If you want 1-tailed p simply divide 2-tailed p by 2.

13 Apr 2011

i'm trying to use your suggested matlab code; mwwtest(x1,x2). But my 2010a matlab version doesn't recognize this code. How is this possible? or is it possible that mwwtest code was deleted since the result is equivalent to ranksum(x1,x2) code?

If that is the case, can i replace mwwtest with ranksum? What is the difference between Mann-whitney u test and wilcoxon ranksum test? My advisor is convinced that Mann-whitney tests the difference btw mean while ranksum tests difference of median or distribution rank.

My final question is if i change to perform ranksum code instead of your suggested mwwtest, ranksum doesn't support 1-tailed test. Is this true? How can I test 1-tailed of ranksum or mwwtest in matlab. I see there are possible way to test 1-tailed in ALGLIB (http://www.alglib.net/hypothesistesting/mannwhitneyu.php).

nuntinee

19 Mar 2010

Thanks, very nice

16 Nov 2009

change in the help section

25 Nov 2009

bug fixed in T computation when n2<n1

23 Dec 2009

Changes in description