cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java
psteitz 2004/12/09 21:18:16 Modified:math/src/test/org/apache/commons/math/stat/inference ChiSquareTestTest.java math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java Log: Increased precision of target values used in tests. Revision ChangesPath 1.5 +9 -7 jakarta-commons/math/src/test/org/apache/commons/math/stat/inference/ChiSquareTestTest.java Index: ChiSquareTestTest.java === RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/inference/ChiSquareTestTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ChiSquareTestTest.java4 Dec 2004 20:52:43 - 1.4 +++ ChiSquareTestTest.java10 Dec 2004 05:18:16 - 1.5 @@ -47,16 +47,16 @@ // 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 @@ 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 @@ 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 */ 1.4 +4 -4 jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Index: SimpleRegressionTest.java === RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SimpleRegressionTest.java 24 Oct 2004 21:47:16 - 1.3 +++ SimpleRegressionTest.java 10 Dec 2004 05:18:16 - 1.4 @@ -117,7 +117,7 @@ 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(),
cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java
psteitz 2004/10/23 23:30:01 Modified:math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java Log: Fixed bugged test (pr #31860), added more R certified tests Revision ChangesPath 1.2 +31 -14 jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Index: SimpleRegressionTest.java === RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- SimpleRegressionTest.java 8 Oct 2004 05:08:20 - 1.1 +++ SimpleRegressionTest.java 24 Oct 2004 06:30:01 - 1.2 @@ -60,11 +60,13 @@ private double[][] infData = { { 15.6, 5.2 }, {26.8, 6.1 }, {37.8, 8.7 }, {36.4, 8.5 }, {35.5, 8.8 }, {18.6, 4.9 }, {15.3, 4.5 }, {7.9, 2.5 }, {0.0, 1.1 } }; - + /* - * From http://www.xycoon.com/simple_linear_regression.htm + * Data with bad linear fit */ -private double[][] infData2 = { { 1, 3 }, {2, 5 }, {3, 7 }, {4, 14 }, {5, 11 }}; +private double[][] infData2 = { { 1, 1 }, {2, 0 }, {3, 5 }, {4, 2 }, +{5, -1 }, {6, 12 } +}; public SimpleRegressionTest(String name) { super(name); @@ -84,6 +86,8 @@ for (int i = 0; i data.length; i++) { regression.addData(data[i][1], data[i][0]); } +// Tests against certified values from +// http://www.itl.nist.gov/div898/strd/lls/data/LINKS/DATA/Norris.dat assertEquals(slope, 1.00211681802045, regression.getSlope(), 10E-12); assertEquals(slope std err, 0.429796848199937E-03, regression.getSlopeStdErr(),10E-12); @@ -100,6 +104,8 @@ regression.getMeanSquareError(), 10E-10); assertEquals(SSE, 26.6173985294224, regression.getSumSquaredErrors(),10E-9); +// End certified data tests + assertEquals( predict(0), -0.262323073774029, regression.predict(0), 10E-12); assertEquals(predict(1), 1.00211681802045 - 0.262323073774029, @@ -185,19 +191,30 @@ } public void testInference() throws Exception { - -SimpleRegression regression = new SimpleRegression(); +//-- verified against R, version 1.8.1 - +// infData +regression = new SimpleRegression(); regression.addData(infData); - -assertEquals(slope confidence interval, 0.0271, -regression.getSlopeConfidenceInterval(), 0.0001); -assertEquals(slope std err,0.01146, -regression.getSlopeStdErr(), 0.0001); - +assertEquals(slope std err, 0.011448491, +regression.getSlopeStdErr(), 1E-10); +assertEquals(std err intercept, 0.286036932, +regression.getInterceptStdErr(),1E-8); +assertEquals(significance, 4.596e-07, +regression.getSignificance(),1E-8); +assertEquals(slope conf interval half-width, 0.0270713794287, +regression.getSlopeConfidenceInterval(),1E-8); +// infData2 regression = new SimpleRegression(); regression.addData(infData2); -assertEquals(significance,0.023331, -regression.getSignificance(),0.0001); +assertEquals(slope std err, 1.07260253, +regression.getSlopeStdErr(), 1E-8); +assertEquals(std err intercept,4.17718672, +regression.getInterceptStdErr(),1E-8); +assertEquals(significance, 0.26183, +regression.getSignificance(),1E-5); +assertEquals(slope conf interval half-width, 2.97802204827, +regression.getSlopeConfidenceInterval(),1E-8); +//- End R-verified tests --- //FIXME: get a real example to test against with alpha = .01 assertTrue(tighter means wider, - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
cvs commit: jakarta-commons/math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java
psteitz 2004/10/24 14:47:16 Modified:math/src/test/org/apache/commons/math/stat/regression SimpleRegressionTest.java Log: Fixed test compile bug introduced in last commit. Revision ChangesPath 1.3 +2 -2 jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java Index: SimpleRegressionTest.java === RCS file: /home/cvs/jakarta-commons/math/src/test/org/apache/commons/math/stat/regression/SimpleRegressionTest.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- SimpleRegressionTest.java 24 Oct 2004 06:30:01 - 1.2 +++ SimpleRegressionTest.java 24 Oct 2004 21:47:16 - 1.3 @@ -193,7 +193,7 @@ public void testInference() throws Exception { //-- verified against R, version 1.8.1 - // infData -regression = new SimpleRegression(); +SimpleRegression regression = new SimpleRegression(); regression.addData(infData); assertEquals(slope std err, 0.011448491, regression.getSlopeStdErr(), 1E-10); - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]