gov.nist.microanalysis.Utility
Class LinearRegression

java.lang.Object
  extended by gov.nist.microanalysis.Utility.LinearRegression

public class LinearRegression
extends java.lang.Object

Implements a class for computing the linear regression (the best fit line in a least-squares sense.)


Constructor Summary
LinearRegression()
          Constructs an object implementing the linear regression for best fitting a line to data points (in a least-squares sense.)
 
Method Summary
 void addData(double[] x, double[] y)
          addData - Add two equal lengthed arrays of data points to the current accumulation.
 void addDatum(double x, double y)
          addDatum - Add a single data point
 void clear()
          clear - Clear the current accumulation and start a new fit.
 double computeX(double y)
          computeX - Computes the x such that y(x) = x*getSlope() + getIntercept();
 double computeY(double x)
          computeY - Computes Y(x) = x*getSlope() + getIntercept();
 double getIntercept()
          getIntercept - Returns the current best estimate of the y-intercept.
 double getR()
          getR - A measure of the goodness of fit to a linear model
 double getRSquared()
          getR - The standard measure of the goodness of fit to a linear model.
 double getSlope()
          getSlope - Returns the current best estimate of the slope.
 void removeDatum(double x, double y)
          removeDatum - Removes a single data point from the set of data to be fit.
 void setData(double[] x, double[] y)
          setData - Clear the current accumulation and add two equal lengthed arrays of data points.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LinearRegression

public LinearRegression()
Constructs an object implementing the linear regression for best fitting a line to data points (in a least-squares sense.)

Method Detail

clear

public void clear()
clear - Clear the current accumulation and start a new fit.


setData

public void setData(double[] x,
                    double[] y)
setData - Clear the current accumulation and add two equal lengthed arrays of data points.

Parameters:
x -
y -

addData

public void addData(double[] x,
                    double[] y)
addData - Add two equal lengthed arrays of data points to the current accumulation.

Parameters:
x -
y -

addDatum

public void addDatum(double x,
                     double y)
addDatum - Add a single data point

Parameters:
x -
y -

removeDatum

public void removeDatum(double x,
                        double y)
removeDatum - Removes a single data point from the set of data to be fit. The values x & y should have been previously added using addDatum(x,y) or as part of an setData() or addData() command otherwise the meaning of the operations performed by removeDatum(...) is not defined as expected. removeDatum(...) does not check to see that the pair x,y were previously added.

Parameters:
x -
y -

getSlope

public double getSlope()
getSlope - Returns the current best estimate of the slope. y(x) = x*getSlope() + getIntercept();

Returns:
double

getIntercept

public double getIntercept()
getIntercept - Returns the current best estimate of the y-intercept. y(x) = x*getSlope() + getIntercept();

Returns:
double

computeY

public double computeY(double x)
computeY - Computes Y(x) = x*getSlope() + getIntercept();

Parameters:
x -
Returns:
double

computeX

public double computeX(double y)
computeX - Computes the x such that y(x) = x*getSlope() + getIntercept();

Parameters:
y -
Returns:
double

getR

public double getR()
getR - A measure of the goodness of fit to a linear model

Returns:
double

getRSquared

public double getRSquared()
getR - The standard measure of the goodness of fit to a linear model. 0 -> does not fit. 1 -> fits a linear model perfectly.

Returns:
double