pamMaths
Class Regressions

java.lang.Object
  extended by pamMaths.Regressions

public class Regressions
extends java.lang.Object

Class for performing various regressions. Relies heavily on the Matrixes and other utilities in the JAMA package. Developers must download JAMA and install the jar file into their JAVA path.

see http://math.nist.gov/javanumerics/jama/

Author:
Douglas Gillespie

Constructor Summary
Regressions()
           
 
Method Summary
private static double[] anyOrderFit(double[] x, double[] y, int order)
          Fit a polynomial of any order
static double getMean(double[] y)
          Get the mean of a set of values
static double[] linFit(double[] x, double[] y)
          Fit a linear regression line to a set of points
static double[] meanFit(double[] y)
          Return the mean of a set of points as a one element array for compatibility with other, higher order fits.
static double[] polyFit(double[] x, double[] y, int order)
           
static double[] squareFit(double[] x, double[] y)
          Fit a second order polynomial to a set of points
static double value(double[] fitParams, double x)
          Use the parameters of the fit to calculate a value using the fitParams polynomial.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Regressions

public Regressions()
Method Detail

polyFit

public static double[] polyFit(double[] x,
                               double[] y,
                               int order)

meanFit

public static double[] meanFit(double[] y)
Return the mean of a set of points as a one element array for compatibility with other, higher order fits.

Parameters:
y - array ofvalues
Returns:
the mean value as a one element array

getMean

public static double getMean(double[] y)
Get the mean of a set of values

Parameters:
y - array ofvalues
Returns:
the mean value

linFit

public static double[] linFit(double[] x,
                              double[] y)
Fit a linear regression line to a set of points

Parameters:
x - array of x coordinates
y - array of y coordinates
Returns:
the two coefficients for the fit

squareFit

public static double[] squareFit(double[] x,
                                 double[] y)
Fit a second order polynomial to a set of points

Parameters:
x - array of x coordinates
y - array of y coordinates
Returns:
the three coefficients for the fit or null if a fit is not possible.

anyOrderFit

private static double[] anyOrderFit(double[] x,
                                    double[] y,
                                    int order)
Fit a polynomial of any order

Parameters:
x - set of x coordinates
y - set of y coordinates
order - order of the fit
Returns:
array of fit coefficients.

value

public static double value(double[] fitParams,
                           double x)
Use the parameters of the fit to calculate a value using the fitParams polynomial.

Parameters:
fitParams - parameters of the fit
x - x value
Returns:
y value = fitParams[0] + fitParams[1]*x + fitParams[2]*x^2, etc...