File Exchange

## Wilcoxon test

version 1.10 (3.66 KB) by

non parametric Wilcoxon test for two paired samples

3.66667
4 Ratings

Updated

This file execute the non parametric Wilcoxon test to evaluate the difference between paired (dependent) samples. If the number of difference is less than 15, the algorithm calculate the exact ranks distribution; else it uses a normal distribution approximation.
Now, the MatLab function SIGNRANK returns the same p-value. Anyway, this Wilcoxon function gives a more detailed output (that is necessary for publications...)

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

lu yer

### lu yer (view profile)

Hello, is my explanation right?

lu yer

### lu yer (view profile)

The table of critical values in my statistic book is derive from this book: Some rapid approximate statistictical procedures. New York: American Cyanamid Company, p.13. I can't find it but in wikipedia.org, I find this table is the same with my book. The website is http://users.sussex.ac.uk/~grahamh/RM1web/WilcoxonTable2005.pdf

lu yer

### lu yer (view profile)

Thank you for your reply! when I change the script TC=[0 0 0 0 0 0 2 3 5 8 10 13 17 21 25 29 34 40 46 52 58 65 73 81 89] and n<25, The results are same with the SPSS calculate. The book is a Chinese book and now I am looking for some paper.

Giuseppe Cardillo

which book?

lu yer

### lu yer (view profile)

Hi, I have a quistion about this script.In this script, if the number of difference is less than 15, the algorithm calculate the exact ranks distribution. I think it should change ‘if the number of difference is less than 25’. Because in my statistic book, it's 25 and the TC (line 117) also should change as TC=[0 0 0 0 0 0 2 3 5 8 10 13 17 21 25 29 34 40 46 52 58 65 73 81 89].

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

if you type: wilcoxon it will works showing the example.

in the other cases you have to write:
x1=[n1 n2 n3 n4 n5...ni];
x2=[m1 m2 m3 m4 m5...mi];
wilcoxon(x1,x2)

where n1...ni are the values of the first vector and m2...mi are the values of the second vector.

Thanks for your reply... actually I'm using a sample that you given in the example.. the error is:

WILCOXON requires vector rather than matrix data'

Then when I change to 'elseif nu<=2'

The result I get are:
w= 325.0000
mw = 0
sW = 73.1608
zW = 4.4354
p-value (2-tailed) = 1.000000000000000e+000

almost same, only p-value is different

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

Madi, I wrote Wilcoxon to manage two vectors and not a matrix.
nu is the number of inputs that you give to the function. If you change nu...I don't know what are you doing...

sorry typo error:

elseif nu<=2

From my previous comment,'WILCOXON requires vector rather than matrix data'

then I change the code to:

'elseif nu<=2' and now OK.. it is true?

Hi, when I follow the example, the this error coming out:

'WILCOXON requires vector rather than matrix data'

What should I do?

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

No it is not normal: ther is a bug on row 152.
The correct command is:
p=min([1 2*normcdf(zW)]); %p-value

I've just upload the correct version
Thank you

JR King

### JR King (view profile)

Hi,
Is it normal that if I do:
stats = wilcoxon(rand(1,100),rand(1,100))
it return a p-value of 0?
Thanks

Shabnam

### Shabnam (view profile)

Thank you very much for the references. Just for the future reference, I would like to emphasize the following points:

1. According to Stanton Glantz's book (Chapter 10), "When there are tied ranks, and we use the normal distribution to compute the
P value, sigma_w needs to be reduced by a factor that depends on the number of ties". You have used this formula in your function.

2. The correction for continuity has been implemented based on the second reference mentioned above (http://faculty.vassar.edu/lowry/ch12a.html)

Please correct any false statement mentioned above.

Thank you very much for your help,
Shabnam

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

A. So, do you mean that "0.5" in Line 123 (zW=(abs(W)-0.5)/sW) is the correction for continuity; however the real mean of the distribution of W is 0?
R. Yes 0.5 is the Yates'es Correction for continuity. If you have a great number of subjects W distribution can be approximated with a normal distribution that has mean=0 and a computed standard deviation.

A. I read a little about the concept of "continuity correction"; however, it seems that those methods including Yates' Correction have not been designed for the normal distribution. I really appreciate if you send me your reference on this particular case (i.e. for the normal distribution)
R. Yates'es correction can be applied in every case in which a discrete distribution is approximated by a continue distribution. If you read well you can find this in Stanton Glantz book, chapter 10. Anyway another (and clear) reference is http://faculty.vassar.edu/lowry/ch12a.html

Regards

Shabnam

### Shabnam (view profile)

Thanks a lot for the prompt response.

So, do you mean that "0.5" in Line 123 (zW=(abs(W)-0.5)/sW) is the correction for continuity; however the real mean of the distribution of W is 0?

I read a little about the concept of "continuity correction"; however, it seems that those methods including Yates' Correction have not been designed for the normal distribution. I really appreciate if you send me your reference on this particular case (i.e. for the normal distribution)

Thank you very much,
Shabnam

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

Dear Shabnam,
first of all you compute W from your data. If the null hypothesisi is true, the signed rank will distribute equally between groups and so W->0. To check if W is not different from 0 you can use the normal approximation. A normal distribution has two parameters: a mean, that in this case is set to 0, and a standard deviation that is computed. Another one point: normal istribution is a continue distribution, but W is discrete. To check W against this normal distribution, it must be normalized: you will compute z=|W|/std. To include the Yates'es correction for continuity: (|W|-0.5)/std.
As you can see zW is not 0.5
Regards

Shabnam

### Shabnam (view profile)

According to Chapter 10 of the book by Stanton A. Glantz (Primer of Biostatistics) and as you mentioned above, mu_w=0 (mu_w is the mean of the distribution of W). My question is why line 123 of your code shows that mean = 0.5 :
zW=(abs(W)-0.5)/sW;

Thanks,
Shabnam

Giuseppe Cardillo

### Giuseppe Cardillo (view profile)

Yes for all questions

Jorge Amaral

### Jorge Amaral (view profile)

Is this test is also called Wilcoxon Signed Rank Test and also Wilcoxon matched pairs?

If the p-value is less than 0.05 can I say that there is a difference between X1 and X2? Like in the example?

Antonio Trujillo-Ortiz

Only to correct and clarify my previous comment, and to recall to all that, with respect to the non parametric tests between two samples, two classes exist: (1) Independent, that can be both of the same size or not, being been able to utilize the Mann-Whitneys test or the Wilcoxon ranks test; and (2) Dependent, that necessarily them should be of the same size, since is the same sample observed in two different circumstances or times, where applies the Wilcoxon signs and ranks test.

Also, I should clarify that in the personal thing I do not use the term unpaired to assign independent samples, since unpaired is synonym of unbalanced; neither paired for assign dependent, since paired is synonym of balanced. This by the fundamental reason that the concepts of independent or dependent arise for the itself nature of the data, and not because they are unpaired or paired.

The m-file here developed by Giuseppe it is a Wilcoxons test for two dependent samples for it is correct his comment that the data vectors must have the same length, and, if it is not, delete those uncoupled data. There isn't any other solutions.

So, my previous review comment is obsolete and should be ignored.

Thanks,

Prof. Antonio Trujillo-Ortiz

Antonio Trujillo-Ortiz

Hi Giuseppe,

You are wrong. According to the non-parametric statistics theoretic fundamentals, there are a two Wilcoxon tests:(1)Wilcoxon Rank Test for two unpaired samples, and(2) Wilcoxon Sign-Rank Test for two paired samples. You must to review them.

Yours,

Prof. Antonio Trujillo-Ortiz

Giuseppe Cardillo

The Wilcoxon's test is a paired test. Infact it test if the differences observed in a group after an event (in exemplum drug subministration) are caused by the event or by chance. If your vectors differ in length you must delete the uncoupled data. I think there isn't any other solutions.

James Cai

If my vectors, X and Y, are different in length, can I use wilcoxon(X,Y)? If not, what's the solution? Thanks.

Giuseppe Cardillo

You have right. I fixed the bug and uploaded the new file.

Good but code need line 57

if min(rowx, colx) > 1 || min(rowy,coly) > 1,

to be replaced with

if((min(rowx1, colx1) > 1) || (min(rowx2,colx2) > 1))

Brahim

Giuseppe Cardillo

ERRATA CORRIGE: the TIEADJ value computed by TIEDRANK is quite different from correction reported in several books. The same for z-value because W is approximated with a normal distribution with mean=0 and std.dev=1. In this algorithm the tie correction is computed as reported in Stanton A. Glantz book and the normal distribution has mean=0 and a calculated std.dev (depending on tie correction).

Giuseppe Cardillo

RANKSUM and SIGNRANK don't compute the correction for the ties.

Jos x@y.z

As this requires the statistics toolbox, the function RANKSUM and SIGNRANK are available to the users. What does this function adds to those two?