Example usage for org.apache.commons.math3.stat.regression SimpleRegression addObservations

List of usage examples for org.apache.commons.math3.stat.regression SimpleRegression addObservations

Introduction

In this page you can find the example usage for org.apache.commons.math3.stat.regression SimpleRegression addObservations.

Prototype

public void addObservations(final double[][] x, final double[] y) throws ModelSpecificationException 

Source Link

Document

Adds a series of observations to the regression model.

Usage

From source file:IBDMUT.Tools.java

public static double[] ApacheRegression(double[][] x, double[] y) {
    if (x.length < 2) {
        //            Tools.warning("******************************************************");
        //            Tools.warning("******************************************************");
        //            Tools.warning("******************************************************");
        //            Tools.warning("Trying to run regression with " + x.length + " points.");
        //            Tools.warning("******************************************************");
        //            Tools.warning("******************************************************");
        //            Tools.warning("******************************************************");
        exit("Trying to run regression with " + x.length + " points.");
    }//from w w w.j a  v a  2 s .  c o m
    if (Tools.loggerIsOn()) {
        Tools.writeLog("Regression");
        Tools.writeLog("\tx\ty");
        for (int i = 0; i < x.length; i++) {
            Tools.writeLog("\t" + x[i][0] + "\t" + y[i]);
        }
    }
    SimpleRegression reg = new SimpleRegression(true);
    reg.addObservations(x, y);
    RegressionResults regRes = reg.regress();
    double[] regResValues = regRes.getParameterEstimates();
    double intercept = regResValues[0];
    double slope = regResValues[1];
    return new double[] { intercept, slope, regRes.getRSquared() };
}