Example usage for org.apache.commons.math.stat.regression SimpleRegression getRSquare

List of usage examples for org.apache.commons.math.stat.regression SimpleRegression getRSquare

Introduction

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

Prototype

public double getRSquare() 

Source Link

Document

Returns the <a href="http://www.xycoon.com/coefficient1.htm"> coefficient of determination</a>, usually denoted r-square.

Usage

From source file:com.discursive.jccook.math.SimpleRegressionExample.java

public static void main(String[] args) throws MathException {

    SimpleRegression sr = new SimpleRegression();

    // Add data points       
    sr.addData(0, 0);/*w  ww .  j a  va  2  s.com*/
    sr.addData(1, 1.2);
    sr.addData(2, 2.6);
    sr.addData(3, 3.2);
    sr.addData(4, 4);
    sr.addData(5, 5);

    NumberFormat format = NumberFormat.getInstance();

    // Print the value of y when line intersects the y axis
    System.out.println("Intercept: " + format.format(sr.getIntercept()));

    // Print the number of data points
    System.out.println("N: " + sr.getN());

    // Print the Slope and the Slop Confidence
    System.out.println("Slope: " + format.format(sr.getSlope()));
    System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval()));

    // Print RSquare a measure of relatedness
    System.out.println("RSquare: " + format.format(sr.getRSquare()));

    sr.addData(400, 100);
    sr.addData(300, 105);
    sr.addData(350, 70);
    sr.addData(200, 50);
    sr.addData(150, 300);
    sr.addData(50, 500);

    System.out.println("Intercept: " + format.format(sr.getIntercept()));
    System.out.println("N: " + sr.getN());
    System.out.println("Slope: " + format.format(sr.getSlope()));
    System.out.println("Slope Confidence: " + format.format(sr.getSlopeConfidenceInterval()));
    System.out.println("RSquare: " + format.format(sr.getRSquare()));

}

From source file:uk.ac.leeds.ccg.andyt.generic.visualisation.charts.Generic_ScatterPlotAndLinearRegression.java

/**
 * @param data double[2][] where: data[0][] are the y values data[1][] are
 * the x values/*w ww.  j a  v a 2 s.  c o m*/
 * @return double[] result where: <ul> <li>result[0] is the y axis
 * intercept;</li> <li>result[1] is the change in y relative to x (gradient
 * or slope);</li> <li>result[2] is the rank correlation coefficient
 * (RSquare);</li> <li>result[3] is data[0].length.</li> </ul>
 */
public static double[] getSimpleRegressionParameters(double[][] data) {
    double[] result = new double[4];
    // org.apache.commons.math.stat.regression.SimpleRegression;
    SimpleRegression a_SimpleRegression = new SimpleRegression();
    //System.out.println("data.length " + data[0].length);
    for (int i = 0; i < data[0].length; i++) {
        a_SimpleRegression.addData(data[1][i], data[0][i]);
        //aSimpleRegression.addData(data[0][i], data[1][i]);
    }
    result[0] = a_SimpleRegression.getIntercept();
    result[1] = a_SimpleRegression.getSlope();
    result[2] = a_SimpleRegression.getRSquare();
    result[3] = data[0].length;
    return result;
}

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

/**
 * data[0][] = observed  SAR/*from   w  w w  .  j  a  v  a2  s . c  om*/
 * data[1][] = expected  CAS
 *
 * @param data
 * @return 
 */
public static double[] printSimpleRegression(double[][] data) {
    double[] result = new double[3];
    // org.apache.commons.math.stat.regression.SimpleRegression;
    SimpleRegression aSimpleRegression = new SimpleRegression();
    System.out.println("data.length " + data[0].length);
    for (int i = 0; i < data[0].length; i++) {
        // aSimpleRegression.addData( data[1][i], data[0][i] );
        aSimpleRegression.addData(data[0][i], data[1][i]);
    }
    double _Intercept = aSimpleRegression.getIntercept();
    double _Slope = aSimpleRegression.getSlope();
    double _RSquare = aSimpleRegression.getRSquare();
    System.out.println(" y = " + _Slope + " * x + " + _Intercept);
    System.out.println(" RSquare " + _RSquare);
    result[0] = _Intercept;
    result[1] = _Slope;
    result[2] = _RSquare;
    return result;
}