Class LinearFit

java.lang.Object
xal.extension.fit.LinearFit

public class LinearFit extends Object
Fit a set of x,y data pairs to a line where y = slope * x + intercept.
  • Field Details

  • Constructor Details

    • LinearFit

      public LinearFit()
      Constructor
  • Method Details

    • addSample

      public void addSample(double x, double y)
      Add a new x,y pair.
    • getSlope

      public double getSlope()
      Get the slope performing a fit if needed.
      Returns:
      the fitted slope
    • getIntercept

      public double getIntercept()
      Get the intercept performing a fit if needed.
      Returns:
      the fitted intercept
    • getCorrelationCoefficient

      public double getCorrelationCoefficient()
      Get the correlation coefficient.
      Returns:
      the correlation coefficient.
    • estimateY

      public double estimateY(double x)
      Estimate the dependent variable (y) given the independent variable (x).
      Parameters:
      x - the independent variable
      Returns:
      the dependent variable
    • getMeanSquareOrdinateError

      public double getMeanSquareOrdinateError()
      Get the mean square error of the y value with respect to the fitted line. The square root of this number gives an indication of the uncertainty in y value estimates under certain assumptions about the error distribution.
      Returns:
      the mean square error of the y value with respect to the fitted line
    • performFitIfNeeded

      protected void performFitIfNeeded()
      Perform a linear fit if the the fit needs to be updated due to newly added data.
    • performFit

      protected void performFit()
      Calculate the slope and intercept.
    • toString

      public String toString()
      Generate a string representation of the linear equation.
      Overrides:
      toString in class Object
      Returns:
      a string representation of the linear equation