Package pamMaths

Class Regressions

java.lang.Object
pamMaths.Regressions

public class Regressions extends 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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Regressions

      public Regressions()
  • Method Details

    • 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.
    • 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...