diff --git a/src/eva2/tools/math/Mathematics.java b/src/eva2/tools/math/Mathematics.java index 1c4b39d5..c0146d4f 100644 --- a/src/eva2/tools/math/Mathematics.java +++ b/src/eva2/tools/math/Mathematics.java @@ -646,6 +646,15 @@ public final class Mathematics { return result; } + /** + * Performs two-sample unpaired t test and returns t critical value. + * + * Both samples have to have the same size and equal variance. + * + * @param vector1 + * @param vector2 + * @return + */ public static double tTestEqSizeEqVar(double[] vector1, double[] vector2) { double n = (double) vector1.length; double mean1 = mean(vector1); diff --git a/test/eva2/tools/math/MathematicsTest.java b/test/eva2/tools/math/MathematicsTest.java index 2fd015e6..5d7a21a8 100644 --- a/test/eva2/tools/math/MathematicsTest.java +++ b/test/eva2/tools/math/MathematicsTest.java @@ -108,4 +108,12 @@ public class MathematicsTest { public void testScale() throws Exception { } + + @Test + public void testTTestEqSizeEqVar() { + double[] values1 = {6,6,2,7,8,8,2,3,5,7,10,5,4,7,5,7,4,5,2,5,3,4,4,4,4}; + double[] values2 = {6,11,8,5,11,8,10,7,4,3,7,6,10,10,6,5,10,11,13,8,5,11,7,8,5}; + + assertEquals(-4.05593, Mathematics.tTestEqSizeEqVar(values1, values2), 0.00001); + } } \ No newline at end of file