Code covered by the BSD License  

Highlights from
Wilcoxon test

4.0

4.0 | 1 rating Rate this file 34 Downloads (last 30 days) File Size: 3.66 KB File ID: #12702
image thumbnail

Wilcoxon test

by Giuseppe Cardillo

 

19 Oct 2006 (Updated 12 Jan 2012)

non parametric Wilcoxon test for two paired samples

| Watch this File

File Information
Description

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
My profile on LinkedIN http://it.linkedin.com/in/giuseppecardillo

Required Products Statistics Toolbox
MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (16)
20 Oct 2006 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?

20 Oct 2006 Giuseppe Cardillo

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

20 Oct 2006 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).

24 Oct 2006 Brahim HAMADICHAREF

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

25 Oct 2006 Giuseppe Cardillo

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

08 Jun 2007 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.

12 Jun 2007 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.

05 Mar 2008 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

07 Mar 2008 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

08 Oct 2010 Jorge Amaral

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?

09 Oct 2010 Giuseppe Cardillo

Yes for all questions

08 May 2011 Shabnam

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

09 May 2011 Giuseppe Cardillo

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

09 May 2011 Shabnam

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

09 May 2011 Giuseppe Cardillo

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

09 May 2011 Shabnam

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

Please login to add a comment or rating.
Updates
23 Oct 2006

m-lint and errors handling improvement

23 Oct 2006

fix in errors messages

23 Oct 2006

improvement

25 Oct 2006

fix bug

30 Oct 2006

Error handling and calculation improvements

10 Mar 2008

Change in DEscription according to Antonio Trujillo-Ortiz comment

24 Sep 2008

Improvement in input error handling

12 Nov 2008

Changes in help section

23 Mar 2009

Little correction in help section to allow a correct copy and paste of the example. Correction in exitus subroutine.

06 Nov 2009

bug correction

11 Nov 2009

The output and the error handling were changed

13 Nov 2009

the STATS struct nargout was added

16 Nov 2009

Changes in help and description sections

23 Dec 2009

Changes in description

23 Mar 2010

I added the plts flag to choose to show the plots

12 Jan 2012

the Hodges-Lehmann estimator of median of differences was added

Tag Activity for this File
Tag Applied By Date/Time
statistics Giuseppe Cardillo 22 Oct 2008 08:44:31
probability Giuseppe Cardillo 22 Oct 2008 08:44:31
wilcoxon Giuseppe Cardillo 22 Oct 2008 08:44:32
paired samples Giuseppe Cardillo 22 Oct 2008 08:44:32
parametric Giuseppe Cardillo 22 Oct 2008 08:44:32
statistics Cristina McIntire 12 Nov 2008 13:56:23
probability Cristina McIntire 12 Nov 2008 13:56:23

Contact us at files@mathworks.com