Increased precision of target values used in tests.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141519 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Phil Steitz 2004-12-10 05:18:16 +00:00
parent 9ac7173ff7
commit 562b3a0b12
2 changed files with 13 additions and 11 deletions

View File

@ -22,7 +22,7 @@ import junit.framework.TestSuite;
/**
* Test cases for the ChiSquareTestImpl class.
*
* @version $Revision: 1.4 $ $Date: 2004/12/04 20:52:43 $
* @version $Revision: 1.5 $ $Date: 2004/12/10 05:18:16 $
*/
public final class ChiSquareTestTest extends TestCase {
@ -47,16 +47,16 @@ public final class ChiSquareTestTest extends TestCase {
// Target values computed using R version 1.8.1
// Some assembly required ;-)
// Use sum((obs - exp)^2/exp) for the chi-square statistic and
// 1 - pchisq(sum((obs - exp)^2/exp), obs.length - 1) for the p-value
// 1 - pchisq(sum((obs - exp)^2/exp), length(obs) - 1) for the p-value
long[] observed = {10, 9, 11};
double[] expected = {10, 10, 10};
assertEquals("chi-square statistic", 0.2, testStatistic.chiSquare(expected, observed), 10E-12);
assertEquals("chi-square p-value", 0.9048374, testStatistic.chiSquareTest(expected, observed), 1E-7);
assertEquals("chi-square p-value", 0.904837418036, testStatistic.chiSquareTest(expected, observed), 1E-10);
long[] observed1 = { 500, 623, 72, 70, 31 };
double[] expected1 = { 485, 541, 82, 61, 37 };
assertEquals( "chi-square test statistic", 16.41311, testStatistic.chiSquare(expected1, observed1), 1E-5);
assertEquals( "chi-square test statistic", 16.4131070362, testStatistic.chiSquare(expected1, observed1), 1E-10);
assertEquals("chi-square p-value", 0.002512096, testStatistic.chiSquareTest(expected1, observed1), 1E-9);
assertTrue("chi-square test reject", testStatistic.chiSquareTest(expected1, observed1, 0.003));
assertTrue("chi-square test accept", !testStatistic.chiSquareTest(expected1, observed1, 0.002));
@ -114,13 +114,13 @@ public final class ChiSquareTestTest extends TestCase {
long[][] counts = { {40, 22, 43}, {91, 21, 28}, {60, 10, 22}};
assertEquals( "chi-square test statistic", 22.709027688, testStatistic.chiSquare(counts), 1E-9);
assertEquals("chi-square p-value", 0.0001448, testStatistic.chiSquareTest(counts), 1E-7);
assertEquals("chi-square p-value", 0.000144751460134, testStatistic.chiSquareTest(counts), 1E-9);
assertTrue("chi-square test reject", testStatistic.chiSquareTest(counts, 0.0002));
assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts, 0.0001));
long[][] counts2 = {{10, 15}, {30, 40}, {60, 90} };
assertEquals( "chi-square test statistic", 0.169, testStatistic.chiSquare(counts2), 1E-3);
assertEquals("chi-square p-value", 0.919, testStatistic.chiSquareTest(counts2), 1E-3);
assertEquals( "chi-square test statistic", 0.168965517241, testStatistic.chiSquare(counts2), 1E-9);
assertEquals("chi-square p-value",0.918987499852, testStatistic.chiSquareTest(counts2), 1E-9);
assertTrue("chi-square test accept", !testStatistic.chiSquareTest(counts2, 0.1));
// ragged input array
@ -179,6 +179,8 @@ public final class ChiSquareTestTest extends TestCase {
new org.apache.commons.math.stat.inference.ChiSquareTestImpl();
double cst = csti.chiSquareTest(exp, obs);
assertEquals("chi-square p-value", 0.0, cst, 1E-3);
assertEquals( "chi-square test statistic",
3624883.342907764, testStatistic.chiSquare(exp, obs), 1E-9);
}
/** Contingency table containing zeros - PR # 32531 */

View File

@ -23,7 +23,7 @@ import junit.framework.TestSuite;
/**
* Test cases for the TestStatistic class.
*
* @version $Revision: 1.3 $ $Date: 2004/10/24 21:47:16 $
* @version $Revision: 1.4 $ $Date: 2004/12/10 05:18:16 $
*/
public final class SimpleRegressionTest extends TestCase {
@ -117,7 +117,7 @@ public final class SimpleRegressionTest extends TestCase {
regression.addData(corrData);
assertEquals("number of observations", 17, regression.getN());
assertEquals("r-square", .896123, regression.getRSquare(), 10E-6);
assertEquals("r", -.946638, regression.getR(), 10E-6);
assertEquals("r", -0.94663767742, regression.getR(), 1E-10);
}
public void testNaNs() {
@ -210,8 +210,8 @@ public final class SimpleRegressionTest extends TestCase {
regression.getSlopeStdErr(), 1E-8);
assertEquals("std err intercept",4.17718672,
regression.getInterceptStdErr(),1E-8);
assertEquals("significance", 0.26183,
regression.getSignificance(),1E-5);
assertEquals("significance", 0.261829133982,
regression.getSignificance(),1E-11);
assertEquals("slope conf interval half-width", 2.97802204827,
regression.getSlopeConfidenceInterval(),1E-8);
//------------- End R-verified tests -------------------------------