Exact p-value computation of the Wilcoxon-Mann-Whitney test

Efficient exact p-value computation of the Wilcoxon-Mann-Whitney test for data without ties (or equivalently tied ranks) can be done in arbitrary precision as shown in our paper. The Mathematica version of the algorithm was made available as a part of the online supplementary materials on the publisher's website. The online supplementary materials also include computation of the Wilcoxon-Mann-Whitney U statistic for data with and without ties and exact albeit less efficient computation of p-value on data with tied ranks. These materials are also available here as attachments at the end of this web page.

The HI-SPEED software packets contain a more comprehensive list of capabilities than those listed in the online supplementary materials. P-value computation by normal approximations for data with and without ties and exact p-value computation on data with ties are some of the additional capabilities within HI-SPEED software packets. Two examples below show how these Java classes are used in a typical application.

Java Class WilcoxonMannWhitneyTest

This Java class implements the Wilcoxon-Mann-Whitney test without tied ranks. The p-value can be computed exactly or approximately via normal approximation. The exact p-value computation is based on a modified version of Harding's algorithm Ref.[1] and was presented in Ref.[2]. Below is an example taken from page 295 of Lothar Sachs' book on Applied Statistics: A handbook of techniques, 2nd Ed. Springer, NY 1984.

Cited References:

[1]. Harding, E.F., 1984. An efficient, minimal-storage procedure for calculating the Mann-Whitney U, Generalized U and similar distributions. Journal of the Royal Statistical Society. Series C (Applied Statistics) 33, 1-6.

[2]. Koay CG, Yeh P-H, Ollinger JM, İrfanoğlu MO, Pierpaoli C, Basser PJ, Oakes TR, Riedy G. Tract Orientation and Angular Dispersion Deviation Indicator (TOADDI): A framework for single-subject analysis in diffusion tensor imaging. NeuroImage 2016; 126: 151-163. DOI: 10.1016/j.neuroimage.2015.11.046

You need the following class:

import cgk.WilcoxonMannWhitneyTestWithTies;

//------------------------------------------------------------------------

public static void wilcoxonMannWhitneyTestExample(){

double[] A = {7,14,22,36,40,48,49,52};

double[] B = {3,5,6,10,17,18,20,39};

boolean useNormalApproximation = false;

WilcoxonMannWhitneyTest wmw = new WilcoxonMannWhitneyTest(A.length,B.length, useNormalApproximation);

double[] results = wmw.runTest(A, B);

System.out.println("p-value by normal approximation? : "+wmw.normalApproximationEmployed() );

System.out.println("Umin = "+results[0]);

System.out.println("p-value = "+results[1]);

//Using static methods to compute the table of exact p-values or approximate p-values.

// Uncomment out the two statements below if you would like to see the exact and approximate p-values.

//System.out.println("Asymptotic p-value = "+MAT.toString( WilcoxonMannWhitneyTest.asymptoticPValueTable(A.length, B.length) ) );

//System.out.println("Exact p-value table ="+MAT.toString(WilcoxonMannWhitneyTest.exactPValueList(A.length, B.length)));

}

//------------------------------------------------------------------------

If "useNormalApproximation" is set to "true", the printout should be

p-value by normal approximation? : true

Umin = 11.0

p-value = 0.027423154381354675

If "useNormalApproximation" is set to "false", the printout should be

p-value by normal approximation? : false

Umin = 11.0

p-value = 0.028127428127428127

Therefore, the p-value by normal approximation is less than the exact p-value.

Java Class WilcoxonMannWhitneyTestWithTies

This Java class implements the Wilcoxon-Mann-Whitney test with tied ranks. The p-value can be computed exactly or approximately via normal approximation. Below is an example taken from page 296 of Lothar Sachs' book on Applied Statistics: A handbook of techniques, 2nd Ed. Springer, NY 1984. The example shown in Sachs' book has several minor errors. For example, R1, R2, U1 and U2 should be 84.5, 51.5, 15.5 and 48.5, respectively.

You need the following class:

import cgk.WilcoxonMannWhitneyTestWithTies;

//---------------------------------------------------------------------

public static void wilcoxonMannWhitneyTestWithTiesExample(){

double[] A = {5,5,8,10,13,13,13,15};

double[] B = {3,3,4,5,5,8,9,16};

boolean useNormalApproximation = true;

WilcoxonMannWhitneyTestWithTies wmw = new WilcoxonMannWhitneyTestWithTies(A,B,useNormalApproximation);

System.out.println( "p-value by normal approximation? : "+wmw.normalApproximationEmployed() );

System.out.println( "Umin = "+wmw.getUmin());

System.out.println( "p-Value = "+wmw.getPValue());

}

//---------------------------------------------------------------------

If "useNormalApproximation" is set to "true", the printout should be

p-value by normal approximation? : true

Umin = 15.5

p-value = 0.07949907143493151

If "useNormalApproximation" is set to "false", the printout should be

p-value by normal approximation? : false

Umin = 15.5

p-value = 0.08873348873348873

Therefore, the p-value by normal approximation is less than the exact p-value.