Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created August 11, 2014 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aconbere/4fef56e5182e510aceb3 to your computer and use it in GitHub Desktop.
Save aconbere/4fef56e5182e510aceb3 to your computer and use it in GitHub Desktop.
Index: src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java
===================================================================
--- src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java (revision 1616791)
+++ src/main/java/org/apache/commons/math3/stat/inference/MannWhitneyUTest.java (working copy)
@@ -145,12 +145,12 @@
* U1 = R1 - (n1 * (n1 + 1)) / 2 where R1 is sum of ranks for sample 1,
* e.g. x, n1 is the number of observations in sample 1.
*/
- final double U1 = sumRankX - (x.length * (x.length + 1)) / 2;
+ final double U1 = sumRankX - ((double) x.length * (x.length + 1)) / 2;
/*
* It can be shown that U1 + U2 = n1 * n2
*/
- final double U2 = x.length * y.length - U1;
+ final double U2 = (double) x.length * y.length - U1;
return FastMath.max(U1, U2);
}
@@ -230,7 +230,7 @@
/*
* It can be shown that U1 + U2 = n1 * n2
*/
- final double Umin = x.length * y.length - Umax;
+ final double Umin = (double) x.length * y.length - Umax;
return calculateAsymptoticPValue(Umin, x.length, y.length);
}
Index: src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java
===================================================================
--- src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java (revision 1616791)
+++ src/test/java/org/apache/commons/math3/stat/inference/MannWhitneyUTestTest.java (working copy)
@@ -112,4 +112,16 @@
double result = testStatistic.mannWhitneyUTest(d1, d2);
Assert.assertTrue(result > 0.1);
}
+
+ @Test
+ public void testReallyBigDataSetSameValues() {
+ double[] d1 = new double[110000];
+ double[] d2 = new double[110000];
+ for (int i = 0; i < 110000; i++) {
+ d1[i] = i;
+ d2[i] = i;
+ }
+ double result = testStatistic.mannWhitneyUTest(d1, d2);
+ Assert.assertTrue(result == 1.0);
+ }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment