Top Description Fields Constructors Methods
org.apache.commons.math3.stat.inference

public Class MannWhitneyUTest

extends Object
Class Inheritance
Imports
org.apache.commons.math3.distribution.NormalDistribution, org.apache.commons.math3.exception.ConvergenceException, .MaxCountExceededException, .NoDataException, .NullArgumentException, org.apache.commons.math3.stat.ranking.NaNStrategy, .NaturalRanking, .TiesStrategy, org.apache.commons.math3.util.FastMath

An implementation of the Mann-Whitney U test (also called Wilcoxon rank-sum test).

Field Summary

Modifier and TypeField and Description
private NaturalRanking
naturalRanking

Ranking algorithm.

Constructor Summary

AccessConstructor and Description
public
MannWhitneyUTest()

Create a test instance using where NaN's are left in place and ties get the average of applicable ranks.

public
MannWhitneyUTest(final NaNStrategy
specifies the strategy that should be used for Double.NaN's
nanStrategy
,
final TiesStrategy
specifies the strategy that should be used for ties
tiesStrategy
)

Create a test instance using the given strategies for NaN's and ties.

Method Summary

Modifier and TypeMethod and Description
private double

Returns:

two-sided asymptotic p-value
calculateAsymptoticPValue
(final double
smallest Mann-Whitney U value
Umin
,
final int
number of subjects in first sample
n1
,
final int
number of subjects in second sample
n2
)

private double[]

Returns:

concatenated array
concatenateSamples
(final double[]
first sample
x
,
final double[]
second sample
y
)

Concatenate the samples into one array.

private void
ensureDataConformance(final double[]
first sample
x
,
final double[]
second sample
y
)

Ensures that the provided arrays fulfills the assumptions.

public double

Returns:

Mann-Whitney U statistic (maximum of Ux and Uy)
mannWhitneyU
(final double[]
the first sample
x
,
final double[]
the second sample
y
)

Computes the Mann-Whitney U statistic comparing mean for two independent samples possibly of different length.

public double

Returns:

asymptotic p-value
mannWhitneyUTest
(final double[]
the first sample
x
,
final double[]
the second sample
y
)

Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U statistic comparing mean for two independent samples.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

naturalRankingback to summary
private NaturalRanking naturalRanking

Ranking algorithm.

Constructor Detail

MannWhitneyUTestback to summary
public MannWhitneyUTest()

Create a test instance using where NaN's are left in place and ties get the average of applicable ranks. Use this unless you are very sure of what you are doing.

MannWhitneyUTestback to summary
public MannWhitneyUTest(final NaNStrategy nanStrategy, final TiesStrategy tiesStrategy)

Create a test instance using the given strategies for NaN's and ties. Only use this if you are sure of what you are doing.

Parameters
nanStrategy:NaNStrategy

specifies the strategy that should be used for Double.NaN's

tiesStrategy:TiesStrategy

specifies the strategy that should be used for ties

Method Detail

calculateAsymptoticPValueback to summary
private double calculateAsymptoticPValue(final double Umin, final int n1, final int n2) throws ConvergenceException, MaxCountExceededException
Parameters
Umin:double

smallest Mann-Whitney U value

n1:int

number of subjects in first sample

n2:int

number of subjects in second sample

Returns:double

two-sided asymptotic p-value

Exceptions
ConvergenceException:
if the p-value can not be computed due to a convergence error
MaxCountExceededException:
if the maximum number of iterations is exceeded
concatenateSamplesback to summary
private double[] concatenateSamples(final double[] x, final double[] y)

Concatenate the samples into one array.

Parameters
x:double[]

first sample

y:double[]

second sample

Returns:double[]

concatenated array

ensureDataConformanceback to summary
private void ensureDataConformance(final double[] x, final double[] y) throws NullArgumentException, NoDataException

Ensures that the provided arrays fulfills the assumptions.

Parameters
x:double[]

first sample

y:double[]

second sample

Exceptions
NullArgumentException:
if x or y are null.
NoDataException:
if x or y are zero-length.
mannWhitneyUback to summary
public double mannWhitneyU(final double[] x, final double[] y) throws NullArgumentException, NoDataException

Computes the Mann-Whitney U statistic comparing mean for two independent samples possibly of different length.

This statistic can be used to perform a Mann-Whitney U test evaluating the null hypothesis that the two independent samples has equal mean.

Let Xi denote the i'th individual of the first sample and Yj the j'th individual in the second sample. Note that the samples would often have different length.

Preconditions:

  • All observations in the two samples are independent.
  • The observations are at least ordinal (continuous are also ordinal).

Parameters
x:double[]

the first sample

y:double[]

the second sample

Returns:double

Mann-Whitney U statistic (maximum of Ux and Uy)

Exceptions
NullArgumentException:
if x or y are null.
NoDataException:
if x or y are zero-length.
mannWhitneyUTestback to summary
public double mannWhitneyUTest(final double[] x, final double[] y) throws NullArgumentException, NoDataException, ConvergenceException, MaxCountExceededException

Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U statistic comparing mean for two independent samples.

Let Xi denote the i'th individual of the first sample and Yj the j'th individual in the second sample. Note that the samples would often have different length.

Preconditions:

  • All observations in the two samples are independent.
  • The observations are at least ordinal (continuous are also ordinal).

Ties give rise to biased variance at the moment. See e.g. http://mlsc.lboro.ac.uk/resources/statistics/Mannwhitney.pdf.

Parameters
x:double[]

the first sample

y:double[]

the second sample

Returns:double

asymptotic p-value

Exceptions
NullArgumentException:
if x or y are null.
NoDataException:
if x or y are zero-length.
ConvergenceException:
if the p-value can not be computed due to a convergence error
MaxCountExceededException:
if the maximum number of iterations is exceeded