Java Statistical Classes

jsc.independentsamples
Class MannWhitneyTest

java.lang.Object
  |
  +--jsc.independentsamples.MannWhitneyTest
All Implemented Interfaces:
PermutableStatistic, SignificanceTest, Statistic

public class MannWhitneyTest
extends Object
implements PermutableStatistic, SignificanceTest

This class represents a Mann-Whitney test. Suppose we have two independent samples from populations A and B. This tests the null hypothesis that A and B have the same distribution against the alternative hypotheses that A and B are different (NOT_EQUAL), or A is stochastically less than B (LESS_THAN), or A is stochastically greater than B (GREATER_THAN).

References:
Freeman,P.R.(1970). Algorithm AS 26: Ranking an array of numbers. Applied Statistics, Vol.19, 111-113.
Siegel,S.(1956). Nonparametric Statistics for the Behavioral Sciences. McGraw-Hill.

Version:
1.0
Author:
A. J. Bertie.

Constructor Summary
MannWhitneyTest(double[] xA, double[] xB)
          Create significance test results.
MannWhitneyTest(double[] xA, double[] xB, H1 alternative)
          Create significance test results.
MannWhitneyTest(double[] xA, double[] xB, H1 alternative, double tolerance, boolean normalApprox)
          Create significance test results.
 
Method Summary
 double approxSP()
          Calculate the approximate significance probability of the test statistic using the normal approximation.
 double exactSP()
          Calculate the exact significance probability of the test statistic.
 int getCorrectionFactor()
          Return correction factor for ties.
 Enumerator getEnumerator()
          Returns a MultiSetPermutations enumerator for generating all possible permutations of the two-sample data.
 int getN()
          Returns the number of observations used to calculate the statistic.
 Rank getRanks()
          Returns the ranks of the combined samples.
 double getRankSumA()
          Returns sum of ranks of sample A.
 double getRankSumB()
          Returns sum of ranks of sample B.
 double getSP()
          Returns the value of the significance probability.
 double getStatistic()
          Returns value of the Mann-Whitney test statistic, U.
 double getTestStatistic()
          Returns value of the Mann-Whitney test statistic, U.
 double getZ()
          Calculate the approximate normal test statistic, z.
 double permuteStatistic(Selection msp)
          Calculate the value of the statistic for a "permutation" of its original data.
 double resampleStatistic(double[] ranksA)
          Calculates the value of the Mann-Whitney statistic for ranks of one of two samples.
 int sizeA()
           
 int sizeB()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MannWhitneyTest

public MannWhitneyTest(double[] xA,
                       double[] xB,
                       H1 alternative,
                       double tolerance,
                       boolean normalApprox)
Create significance test results.

For very large sample sizes the time taken to calculate the exact distribution of the Mann-Whitney U-statistic can be excessive: the option of using a normal approximation is therefore provided.

Parameters:
xA - the data of sample A.
xB - the data of sample B.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
tolerance - the tolerance for tied ranks: two values are treated as equal if the absolute difference between them is less than or equal to this.
normalApprox - if true, a normal approximation is used to calculate the significance probability.
Throws:
IllegalArgumentException - if less than 2 values in either sample.

MannWhitneyTest

public MannWhitneyTest(double[] xA,
                       double[] xB,
                       H1 alternative)
Create significance test results. The tolerance for tied ranks is set to zero. The normal approximation to the null distribution of the Mann-Whitney U-statistic is used to calculate the significance probability if either sample size is greater than 20; otherwise the exact null distribution is used.

Parameters:
xA - the data of sample A.
xB - the data of sample B.
alternative - code indicating the alternative hypothesis: LESS_THAN, NOT_EQUAL, or GREATER_THAN
Throws:
IllegalArgumentException - if less than 2 values in either sample.

MannWhitneyTest

public MannWhitneyTest(double[] xA,
                       double[] xB)
Create significance test results. The alternative hypothesis is NOT_EQUAL. The tolerance for tied ranks is set to zero. The normal approximation to the null distribution of the Mann-Whitney U-statistic is used to calculate the significance probability if either sample size is greater than 20; otherwise the exact null distribution is used.

Parameters:
xA - the data of sample A.
xB - the data of sample B.
Method Detail

approxSP

public double approxSP()
Calculate the approximate significance probability of the test statistic using the normal approximation. A correction is made for tied ranks.

Returns:
the approximate SP.

exactSP

public double exactSP()
Calculate the exact significance probability of the test statistic.

Note that exact SP and critical values for small samples with no ties can also be obtained from the MannWhitneyU class.

Returns:
the exact SP.

getCorrectionFactor

public int getCorrectionFactor()
Return correction factor for ties. This is the integer quantity t as defined by Freeman (1970,p.111). It is used to correct the standard deviation in the normal approximation to the null distribution of U.

Returns:
the correction factor.

getEnumerator

public Enumerator getEnumerator()
Returns a MultiSetPermutations enumerator for generating all possible permutations of the two-sample data.

Specified by:
getEnumerator in interface PermutableStatistic
Returns:
the multi-set permutation enumerator.

getN

public int getN()
Description copied from interface: Statistic
Returns the number of observations used to calculate the statistic.

Specified by:
getN in interface Statistic
Returns:
the sample size.

getRanks

public Rank getRanks()
Returns the ranks of the combined samples. Ranks 0 to nA-1 are the ranks of sample A, ranks nA to nB-1 are the ranks of sample B; where nA and nB are the sizes of samples A and B.

Returns:
the rank structure.

getRankSumA

public double getRankSumA()
Returns sum of ranks of sample A. (Used in the Wilcoxon version of the test.)

Returns:
the rank sum.

getRankSumB

public double getRankSumB()
Returns sum of ranks of sample B. (Used in the Wilcoxon version of the test.)

Returns:
the rank sum.

getSP

public double getSP()
Returns the value of the significance probability. This is the exact or approximate SP - depending on which was specified in the constructor.

Specified by:
getSP in interface SignificanceTest
Returns:
the value of the significance probability.

getStatistic

public double getStatistic()
Returns value of the Mann-Whitney test statistic, U.

Specified by:
getStatistic in interface Statistic
Returns:
the value of U.

getTestStatistic

public double getTestStatistic()
Returns value of the Mann-Whitney test statistic, U.

Specified by:
getTestStatistic in interface SignificanceTest
Returns:
the value of U.

getZ

public double getZ()
Calculate the approximate normal test statistic, z. This is the variate-value of the standard normal distribution used to calculate the approximate significance probability. A correction is made for tied ranks. See Siegel (1956, p.125).

Returns:
the z-value.

permuteStatistic

public double permuteStatistic(Selection msp)
Description copied from interface: PermutableStatistic
Calculate the value of the statistic for a "permutation" of its original data.

Specified by:
permuteStatistic in interface PermutableStatistic
Parameters:
msp - the permutation.
Returns:
the statistic.

resampleStatistic

public double resampleStatistic(double[] ranksA)
Calculates the value of the Mann-Whitney statistic for ranks of one of two samples. The specified ranks will be permutations of the ranks of the original data.

Parameters:
ranksA - ranks of sample A.
Returns:
the Mann-Whitney test statistic.

sizeA

public int sizeA()
Returns:
size of sample A.

sizeB

public int sizeB()
Returns:
size of sample B.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005