@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); }
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; }
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; } }
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; }  }
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); }
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);  }