Example usage for org.apache.commons.math3.stat.regression RegressionResults getRSquared

List of usage examples for org.apache.commons.math3.stat.regression RegressionResults getRSquared

Introduction

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

Prototype

public double getRSquared() 

Source Link

Document

<p>Returns the <a href="http://www.xycoon.com/coefficient1.htm"> coefficient of multiple determination</a>, usually denoted r-square.</p> <p><strong>Preconditions</strong>: <ul> <li>At least numberOfParameters observations (with at least numberOfParameters different x values) must have been added before invoking this method.

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  www . j  a  v  a 2 s . co  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() };
}