Example usage for org.jfree.data.statistics Regression getOLSRegression

List of usage examples for org.jfree.data.statistics Regression getOLSRegression

Introduction

In this page you can find the example usage for org.jfree.data.statistics Regression getOLSRegression.

Prototype

public static double[] getOLSRegression(double[][] data) 

Source Link

Document

Returns the parameters 'a' and 'b' for an equation y = a + bx, fitted to the data using ordinary least squares regression.

Usage

From source file:com.sigueros.charts.LinearRegressionExample.java

/**
 * Creates a sample dataset for Linear data
 *///from  ww  w. j a v  a 2s .  co m

private TimeSeriesCollection createDatasetLinear() {

    final TimeSeries linearData = new TimeSeries("Linear");

    //The Linear dataSet is the Linear Regression:
    double ad[] = Regression.getOLSRegression(getData());

    for (int i = 0; i < getData().length; i++) {
        //The formula to calculate the value is a + b * x, where a = ad[0] and b = ad [1]
        linearData.add(new Year((int) getData()[i][0]), ad[0] + ad[1] * getData()[i][0]);
    }

    TimeSeriesCollection dataLinearCollection = new TimeSeriesCollection();
    dataLinearCollection.addSeries(linearData);

    return dataLinearCollection;

}

From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport.java

/**
 * data[0][] = observed data[1][] = expected
 * @param data/*from   w w  w  .j av  a2  s.  c  o  m*/
 * @return 
 */
public static double[] printOLSRegression(double[][] data) {
    double[][] flipData = new double[data[0].length][2];
    for (int j = 0; j < data[0].length; j++) {
        for (int k = 0; k < 2; k++) {
            // flipData[j][ 1 - k ] = data[ k ][ j ];
            flipData[j][k] = data[k][j];
        }
    }
    // double[] a_RegressionParameters = Regression.getOLSRegression( data
    // );
    double[] a_RegressionParameters = Regression.getOLSRegression(flipData);
    System.out.println("y = " + a_RegressionParameters[1] + " * x + " + a_RegressionParameters[0]);
    return a_RegressionParameters;
}