psteitz 2004/05/31 17:44:24
Modified: math/src/java/org/apache/commons/math/stat/inference
TTestImpl.java
math/src/test/org/apache/commons/math/stat/inference
TTestTest.java
Log:
Added implementation for paired t-test boolean method.
Revision Changes Path
1.4 +37 -9
jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/TTestImpl.java
Index: TTestImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/stat/inference/TTestImpl.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TTestImpl.java 24 May 2004 05:29:05 -0000 1.3
+++ TTestImpl.java 1 Jun 2004 00:44:24 -0000 1.4
@@ -80,16 +80,44 @@
(double) sample1.length);
}
- /* (non-Javadoc)
- * @see org.apache.commons.math.stat.inference.TTest#pairedTTest(double[],
double[], double)
+ /**
+ * Performs a paired t-test</a> evaluating that null hypothesis that the
+ * mean of the paired differences between <code>sample1</code> and
+ * <code>sample2</code> is 0 in favor of the two-sided alternative that the
+ * mean paired difference is not equal to 0, with significance level
+ * <code>alpha</code>.
+ * <p>
+ * Returns <code>true</code> iff the null hypothesis can be rejected with
+ * confidence <code>1 - alpha</code>. To perform a 1-sided test, use
+ * <code>alpha / 2</code>
+ * <p>
+ * <strong>Usage Note:</strong><br>
+ * The validity of the test depends on the assumptions of the parametric
+ * t-test procedure, as discussed
+ * <a
href="http://www.basic.nwu.edu/statguidefiles/ttest_unpaired_ass_viol.html">
+ * here</a>
+ * <p>
+ * <strong>Preconditions</strong>: <ul>
+ * <li>The input array lengths must be the same and their common length
+ * must be at least 2.
+ * </li>
+ * <li> <code> 0 < alpha < 0.5 </code>
+ * </li></ul>
+ *
+ * @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);
}
/**
1.4 +6 -3
jakarta-commons/math/src/test/org/apache/commons/math/stat/inference/TTestTest.java
Index: TTestTest.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/inference/TTestTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TTestTest.java 24 May 2004 05:34:30 -0000 1.3
+++ TTestTest.java 1 Jun 2004 00:44:24 -0000 1.4
@@ -237,11 +237,14 @@
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));
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]