Class MannWhitneyUTest
The definitions and computing formulas used in this implementation follow those in the article, Mann-Whitney U Test
In general, results correspond to (and have been tested against) the R
wilcox.test function, with exact
meaning the same thing in both APIs
and CORRECT
uniformly true in this implementation. For example,
wilcox.test(x, y, alternative = "two.sided", mu = 0, paired = FALSE, exact = FALSE
correct = TRUE) will return the same p-value as mannWhitneyUTest(x, y,
false). The minimum of the W value returned by R for wilcox.test(x, y...) and
wilcox.test(y, x...) should equal mannWhitneyU(x, y...).
-
Constructor Summary
ConstructorDescriptionCreate a test instance using where NaN's are left in place and ties get the average of applicable ranks.MannWhitneyUTest
(NaNStrategy nanStrategy, TiesStrategy tiesStrategy) Create a test instance using the given strategies for NaN's and ties. -
Method Summary
Modifier and TypeMethodDescriptiondouble
mannWhitneyU
(double[] x, double[] y) Computes the Mann-Whitney U statistic comparing means for two independent samples possibly of different lengths.double
mannWhitneyUTest
(double[] x, double[] y) Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U Test comparing means for two independent samples.double
mannWhitneyUTest
(double[] x, double[] y, boolean exact) Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U Test comparing means for two independent samples.
-
Constructor Details
-
MannWhitneyUTest
public MannWhitneyUTest()Create a test instance using where NaN's are left in place and ties get the average of applicable ranks. -
MannWhitneyUTest
Create a test instance using the given strategies for NaN's and ties.- Parameters:
nanStrategy
- specifies the strategy that should be used for Double.NaN'stiesStrategy
- specifies the strategy that should be used for ties
-
-
Method Details
-
mannWhitneyU
public double mannWhitneyU(double[] x, double[] y) throws MathIllegalArgumentException, NullArgumentException Computes the Mann-Whitney U statistic comparing means for two independent samples possibly of different lengths.This statistic can be used to perform a Mann-Whitney U test evaluating the null hypothesis that the two independent samples have 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 can have different lengths.
Preconditions:
- All observations in the two samples are independent.
- The observations are at least ordinal (continuous are also ordinal).
- Parameters:
x
- the first sampley
- the second sample- Returns:
- Mann-Whitney U statistic (minimum of Ux and Uy)
- Throws:
NullArgumentException
- ifx
ory
arenull
.MathIllegalArgumentException
- ifx
ory
are zero-length.
-
mannWhitneyUTest
public double mannWhitneyUTest(double[] x, double[] y) throws MathIllegalArgumentException, NullArgumentException Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U Test comparing means 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.
Preconditions:
- All observations in the two samples are independent.
- The observations are at least ordinal.
If there are no ties in the data and both samples are small (less than or equal to 50 values in the combined dataset), an exact test is performed; otherwise the test uses the normal approximation (with continuity correction).
If the combined dataset contains ties, the variance used in the normal approximation is bias-adjusted using the formula in the reference above.
- Parameters:
x
- the first sampley
- the second sample- Returns:
- approximate 2-sized p-value
- Throws:
NullArgumentException
- ifx
ory
arenull
.MathIllegalArgumentException
- ifx
ory
are zero-length
-
mannWhitneyUTest
public double mannWhitneyUTest(double[] x, double[] y, boolean exact) throws MathIllegalArgumentException, NullArgumentException Returns the asymptotic observed significance level, or p-value, associated with a Mann-Whitney U Test comparing means 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.
Preconditions:
- All observations in the two samples are independent.
- The observations are at least ordinal.
If
exact
istrue
, the p-value reported is exact, computed using the exact distribution of the U statistic. The computation in this case requires storage on the order of the product of the two sample sizes, so this should not be used for large samples.If
exact
isfalse
, the normal approximation is used to estimate the p-value.If the combined dataset contains ties and
exact
istrue
, MathIllegalArgumentException is thrown. Ifexact
isfalse
and the ties are present, the variance used to compute the approximate p-value in the normal approximation is bias-adjusted using the formula in the reference above.- Parameters:
x
- the first sampley
- the second sampleexact
- true means compute the p-value exactly, false means use the normal approximation- Returns:
- approximate 2-sided p-value
- Throws:
NullArgumentException
- ifx
ory
arenull
.MathIllegalArgumentException
- ifx
ory
are zero-length or ifexact
istrue
and ties are present in the data
-