diff --git a/src/java/org/apache/commons/math/stat/inference/TTestImpl.java b/src/java/org/apache/commons/math/stat/inference/TTestImpl.java index 8030d6f8f..74cb22905 100644 --- a/src/java/org/apache/commons/math/stat/inference/TTestImpl.java +++ b/src/java/org/apache/commons/math/stat/inference/TTestImpl.java @@ -26,7 +26,7 @@ import org.apache.commons.math.stat.univariate.StatisticalSummary; /** * Implements t-test statistics defined in the {@link TTest} interface. * - * @version $Revision: 1.3 $ $Date: 2004/05/24 05:29:05 $ + * @version $Revision: 1.4 $ $Date: 2004/06/01 00:44:24 $ */ public class TTestImpl implements TTest, Serializable { @@ -80,16 +80,44 @@ public class TTestImpl implements TTest, Serializable { (double) sample1.length); } - /* (non-Javadoc) - * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[], double[], double) + /** + * Performs a paired t-test evaluating that null hypothesis that the + * mean of the paired differences between sample1 and + * sample2 is 0 in favor of the two-sided alternative that the + * mean paired difference is not equal to 0, with significance level + * alpha. + *

+ * Returns true iff the null hypothesis can be rejected with + * confidence 1 - alpha. To perform a 1-sided test, use + * alpha / 2 + *

+ * Usage Note:
+ * The validity of the test depends on the assumptions of the parametric + * t-test procedure, as discussed + * + * here + *

+ * Preconditions:

+ * + * @param sample1 array of sample data values + * @param sample2 array of sample data values + * @param alpha significance level of the test + * @return true if the null hypothesis can be rejected with + * confidence 1 - alpha + * @throws IllegalArgumentException if the preconditions are not met + * @throws MathException if an error occurs performing the test */ - public boolean pairedTTest( - double[] sample1, - double[] sample2, - double alpha) + public boolean pairedTTest(double[] sample1, double[] sample2, double alpha) throws IllegalArgumentException, MathException { - // TODO Auto-generated method stub - return false; + if ((alpha <= 0) || (alpha > 0.5)) { + throw new IllegalArgumentException("bad significance level: " + alpha); + } + return (pairedTTest(sample1, sample2) < alpha); } /** diff --git a/src/test/org/apache/commons/math/stat/inference/TTestTest.java b/src/test/org/apache/commons/math/stat/inference/TTestTest.java index 208614021..788bc6159 100644 --- a/src/test/org/apache/commons/math/stat/inference/TTestTest.java +++ b/src/test/org/apache/commons/math/stat/inference/TTestTest.java @@ -23,7 +23,7 @@ import org.apache.commons.math.stat.univariate.SummaryStatistics; /** * Test cases for the TTestImpl class. * - * @version $Revision: 1.3 $ $Date: 2004/05/24 05:34:30 $ + * @version $Revision: 1.4 $ $Date: 2004/06/01 00:44:24 $ */ public final class TTestTest extends TestCase { @@ -237,11 +237,14 @@ public final class TTestTest extends TestCase { public void testPaired() throws Exception { double[] sample1 = {1d, 3d, 5d, 7d}; double[] sample2 = {0d, 6d, 11d, 2d}; - double[] sample3 = {0d, 2d}; + double[] sample3 = {5d, 7d, 8d, 10d}; + double[] sample4 = {0d, 2d}; // Target values computed using R, version 1.8.1 (linux version) assertEquals(-0.3133, testStatistic.pairedT(sample1, sample2), 1E-4); assertEquals(0.774544295819, testStatistic.pairedTTest(sample1, sample2), 1E-10); - + assertEquals(0.001208, testStatistic.pairedTTest(sample1, sample3), 1E-6); + assertFalse(testStatistic.pairedTTest(sample1, sample3, .001)); + assertTrue(testStatistic.pairedTTest(sample1, sample3, .002)); } }