예제 #1
0
  public void testNaNs() {
    SimpleRegression regression = new SimpleRegression();
    assertTrue("intercept not NaN", Double.isNaN(regression.getIntercept()));
    assertTrue("slope not NaN", Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("e not NaN", Double.isNaN(regression.getR()));
    assertTrue("r-square not NaN", Double.isNaN(regression.getRSquare()));
    assertTrue("RSS not NaN", Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE not NaN", Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("SSTO not NaN", Double.isNaN(regression.getTotalSumSquares()));
    assertTrue("predict not NaN", Double.isNaN(regression.predict(0)));

    regression.addData(1, 2);
    regression.addData(1, 3);

    // No x variation, so these should still blow...
    assertTrue("intercept not NaN", Double.isNaN(regression.getIntercept()));
    assertTrue("slope not NaN", Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("e not NaN", Double.isNaN(regression.getR()));
    assertTrue("r-square not NaN", Double.isNaN(regression.getRSquare()));
    assertTrue("RSS not NaN", Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE not NaN", Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("predict not NaN", Double.isNaN(regression.predict(0)));

    // but SSTO should be OK
    assertTrue("SSTO NaN", !Double.isNaN(regression.getTotalSumSquares()));

    regression = new SimpleRegression();

    regression.addData(1, 2);
    regression.addData(3, 3);

    // All should be OK except MSE, s(b0), s(b1) which need one more df
    assertTrue("interceptNaN", !Double.isNaN(regression.getIntercept()));
    assertTrue("slope NaN", !Double.isNaN(regression.getSlope()));
    assertTrue("slope std err not NaN", Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err not NaN", Double.isNaN(regression.getInterceptStdErr()));
    assertTrue("MSE not NaN", Double.isNaN(regression.getMeanSquareError()));
    assertTrue("r NaN", !Double.isNaN(regression.getR()));
    assertTrue("r-square NaN", !Double.isNaN(regression.getRSquare()));
    assertTrue("RSS NaN", !Double.isNaN(regression.getRegressionSumSquares()));
    assertTrue("SSE NaN", !Double.isNaN(regression.getSumSquaredErrors()));
    assertTrue("SSTO NaN", !Double.isNaN(regression.getTotalSumSquares()));
    assertTrue("predict NaN", !Double.isNaN(regression.predict(0)));

    regression.addData(1, 4);

    // MSE, MSE, s(b0), s(b1) should all be OK now
    assertTrue("MSE NaN", !Double.isNaN(regression.getMeanSquareError()));
    assertTrue("slope std err NaN", !Double.isNaN(regression.getSlopeStdErr()));
    assertTrue("intercept std err NaN", !Double.isNaN(regression.getInterceptStdErr()));
  }
예제 #2
0
 // Jira MATH-85 = Bugzilla 39432
 public void testSSENonNegative() {
   double[] y = {8915.102, 8919.302, 8923.502};
   double[] x = {1.107178495E2, 1.107264895E2, 1.107351295E2};
   SimpleRegression reg = new SimpleRegression();
   for (int i = 0; i < x.length; i++) {
     reg.addData(x[i], y[i]);
   }
   assertTrue(reg.getSumSquaredErrors() >= 0.0);
 }
예제 #3
0
 public void testPerfect() throws Exception {
   SimpleRegression regression = new SimpleRegression();
   int n = 100;
   for (int i = 0; i < n; i++) {
     regression.addData(((double) i) / (n - 1), i);
   }
   assertEquals(0.0, regression.getSignificance(), 1.0e-5);
   assertTrue(regression.getSlope() > 0.0);
   assertTrue(regression.getSumSquaredErrors() >= 0.0);
 }
예제 #4
0
  public void testNorris() {
    SimpleRegression regression = new SimpleRegression();
    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);
    assertEquals("number of observations", 36, regression.getN());
    assertEquals("intercept", -0.262323073774029, regression.getIntercept(), 10E-12);
    assertEquals("std err intercept", 0.232818234301152, regression.getInterceptStdErr(), 10E-12);
    assertEquals("r-square", 0.999993745883712, regression.getRSquare(), 10E-12);
    assertEquals("SSR", 4255954.13232369, regression.getRegressionSumSquares(), 10E-9);
    assertEquals("MSE", 0.782864662630069, 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, regression.predict(1), 10E-12);
  }