diff --git a/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java b/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java index a4acf2f63..a16173723 100644 --- a/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java +++ b/src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java @@ -170,11 +170,11 @@ public class MannWhitneyUTest { final int n2) throws ConvergenceException, MaxCountExceededException { - final int n1n2prod = n1 * n2; + final double n1n2prod = n1 * n2; // http://en.wikipedia.org/wiki/Mann%E2%80%93Whitney_U#Normal_approximation - final double EU = (double) n1n2prod / 2.0; - final double VarU = (double) (n1n2prod * (n1 + n2 + 1)) / 12.0; + final double EU = n1n2prod / 2.0; + final double VarU = n1n2prod * (n1 + n2 + 1) / 12.0; final double z = (Umin - EU) / FastMath.sqrt(VarU); diff --git a/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java b/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java index 803292205..025520867 100644 --- a/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java +++ b/src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java @@ -100,4 +100,16 @@ public class MannWhitneyUTestTest { // expected } } + + @Test + public void testBigDataSet() throws Exception { + double[] d1 = new double[1500]; + double[] d2 = new double[1500]; + for (int i = 0; i < 1500; i++) { + d1[i] = 2 * i; + d2[i] = 2 * i + 1; + } + double result = testStatistic.mannWhitneyUTest(d1, d2); + Assert.assertTrue(result > 0.1); + } }