icb-stats API icb-stats-31 (20120309094430)

edu.cornell.med.icb.stat
Class LinearRegression

java.lang.Object
  extended by edu.cornell.med.icb.stat.LinearRegression

public class LinearRegression
extends Object

This class performs a Linear Regression. It is based on the formula from http://phoenix.phys.clemson.edu/tutorials/regression/index.html This asumes the relationship between the sets of data (x and y) is linear. I verified the values including correlation coefficient using Excel with the method described in http://phoenix.phys.clemson.edu/tutorials/excel/regression.html


Constructor Summary
LinearRegression()
          Create a linear regression calculator.
 
Method Summary
 void addDataPoint(double x, double y)
          Add a point to the linear regression calculation.
 void addDataPoints(double[] x, double[] y)
          Add a points to the linear regression calculation.
 double getCorrelationCoefficient()
          Obtain the correlation coefficient.
 double getSlope()
          Obtain the slope.
 double getXIntercept()
          Obtain the x-intercept.
 double getYIntercept()
          Obtain the y-intercept.
 void regress()
          Run the regression.
 void reset()
          Prepare for a new regression calculation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearRegression

public LinearRegression()
Create a linear regression calculator.

Method Detail

addDataPoint

public void addDataPoint(double x,
                         double y)
Add a point to the linear regression calculation.

Parameters:
x - the x value of the point being added
y - the y value of the point being added

addDataPoints

public void addDataPoints(double[] x,
                          double[] y)
Add a points to the linear regression calculation. Variables x and y need to be the same length.

Parameters:
x - the array of x values of the points being added
y - the array of y values of the points being added

reset

public void reset()
Prepare for a new regression calculation.


regress

public void regress()
Run the regression. This should be done before calling any of getXIntercept(), getYIntercept(), getSlope(), or getCorrelationCoefficient().


getXIntercept

public double getXIntercept()
Obtain the x-intercept. regress() should be called before calling any of getXIntercept(), getYIntercept(), getSlope(), or getCorrelationCoefficient().

Returns:
the x-intercept

getYIntercept

public double getYIntercept()
Obtain the y-intercept. regress() should be called before calling any of getXIntercept(), getYIntercept(), getSlope(), or getCorrelationCoefficient().

Returns:
the x-intercept

getSlope

public double getSlope()
Obtain the slope. regress() should be called before calling any of getXIntercept(), getYIntercept(), getSlope(), or getCorrelationCoefficient().

Returns:
the slope

getCorrelationCoefficient

public double getCorrelationCoefficient()
Obtain the correlation coefficient. regress() should be called before calling any of getXIntercept(), getYIntercept(), getSlope(), or getCorrelationCoefficient().

Returns:
the slope

icb-stats API icb-stats-31 (20120309094430)

Copyright © 2008-2012 Institute for Computational Biomedicine, All Rights Reserved.