### Question:
Regression { public static double[] getOLSRegression(double[][] data) { int n = data.length; if (n < 2) { throw new IllegalArgumentException("Not enough data."); } double sumX = 0; double sumY = 0; double sumXX = 0; double sumXY = 0; for (double[] aData : data) { double x = aData[0]; double y = aData[1]; sumX += x; sumY += y; double xx = x * x; sumXX += xx; double xy = x * y; sumXY += xy; } double sxx = sumXX - (sumX * sumX) / n; double sxy = sumXY - (sumX * sumY) / n; double xbar = sumX / n; double ybar = sumY / n; double[] result = new double[2]; result[1] = sxy / sxx; result[0] = ybar - result[1] * xbar; return result; }  static double[] getOLSRegression(double[][] data); static double[] getOLSRegression(XYDataset data, int series); static double[] getPowerRegression(double[][] data); static double[] getPowerRegression(XYDataset data, int series); static double[] getPolynomialRegression(XYDataset dataset, 
            int series, int order);  }### Answer:
@Test public void testOLSRegression1a() { double[][] data = createSampleData1(); double[] result1 = Regression.getOLSRegression(data); assertEquals(.25680930, result1[0], 0.0000001); assertEquals(0.72792106, result1[1], 0.0000001); }
@Test public void testOLSRegression1b() { double[][] data = createSampleData1(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 11; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result2 = Regression.getOLSRegression(ds, 0); assertEquals(.25680930, result2[0], 0.0000001); assertEquals(0.72792106, result2[1], 0.0000001); }
@Test public void testOLSRegression2a() { double[][] data = createSampleData2(); double[] result = Regression.getOLSRegression(data); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); }
@Test public void testOLSRegression2b() { double[][] data = createSampleData2(); XYSeries series = new XYSeries("Test"); for (int i = 0; i < 10; i++) { series.add(data[i][0], data[i][1]); } XYDataset ds = new XYSeriesCollection(series); double[] result = Regression.getOLSRegression(ds, 0); assertEquals(53.9729697, result[0], 0.0000001); assertEquals(-4.1823030, result[1], 0.0000001); }