Package com.irurueta.numerical.fitting
Class StraightLineFitter
java.lang.Object
com.irurueta.numerical.fitting.Fitter
com.irurueta.numerical.fitting.StraightLineFitter
Fits provided data (x,y) to a straight line following equation y = a + b*x,
estimates parameters a and b their variances, covariance and their chi square
value.
This class is based on the implementation available at Numerical Recipes
3rd Ed, page 784.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double
Estimated "a" parameter of line following equation y = a + b*xprivate double
Estimated "b" parameter of line following equation y = a + b*Xprivate double
Estimated chi square value.private double
Estimated goodness-of-fit probability (i.e.private double[]
Standard deviations of each pair of points (x,y).private double
Estimated standard deviation of parameter "a".private double
Estimated standard deviation of parameter "b".private double
Estimated standard deviation of provided input data.private double[]
Array containing x coordinates of input data to be fitted to a straight line.private double[]
Array containing y coordinates of input data to be fitted to a straight line.Fields inherited from class com.irurueta.numerical.fitting.Fitter
resultAvailable
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.StraightLineFitter
(double[] x, double[] y) Constructor.StraightLineFitter
(double[] x, double[] y, double[] sig) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
fit()
Fits a straight line following equation y = a + b*x to provided data (x, y) so that parameters associated a, b can be estimated along with their variances, covariance and chi square value.private void
Fits data when standard deviations of input data is not provided.private void
Fits data when standard deviations of input data is provided.double
getA()
Returns estimated "a" parameter of line following equation y = a + b*xdouble
getB()
Returns estimated "b" parameter of line following equation y = a + b*xdouble
getChi2()
Returns estimated chi square value.double
getQ()
Returns estimated goodness-of-fit probability (i.e.double[]
getSig()
Returns standard deviations of each pair of points (x,y).double
getSigA()
Returns estimated standard deviation of parameter "a".double
getSigB()
Returns estimated standard deviation of parameter "b".double
Returns estimated standard deviation of provided input data.double[]
getX()
Returns array containing x coordinates of input data to be fitted to a straight line.double[]
getY()
Returns array containing y coordinates of input data to be fitted to a straight line.boolean
isReady()
Indicates whether this instance is ready because enough input data has been provided to start the fitting process.final void
setInputData
(double[] x, double[] y) Sets input data to fit a straight line to.final void
setInputDataAndStandardDeviations
(double[] x, double[] y, double[] sig) Sets input data and standard deviations of input data to fit a straight line to.Methods inherited from class com.irurueta.numerical.fitting.Fitter
isResultAvailable
-
Field Details
-
x
private double[] xArray containing x coordinates of input data to be fitted to a straight line. -
y
private double[] yArray containing y coordinates of input data to be fitted to a straight line. -
sig
private double[] sigStandard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points. -
a
private double aEstimated "a" parameter of line following equation y = a + b*x -
b
private double bEstimated "b" parameter of line following equation y = a + b*X -
siga
private double sigaEstimated standard deviation of parameter "a". -
sigb
private double sigbEstimated standard deviation of parameter "b". -
chi2
private double chi2Estimated chi square value. -
q
private double qEstimated goodness-of-fit probability (i.e. that the fit would have a chi square value equal or larger than the estimated one). -
sigdat
private double sigdatEstimated standard deviation of provided input data. This is only estimated if array of standard deviations of input points is not provided.
-
-
Constructor Details
-
StraightLineFitter
public StraightLineFitter()Constructor. -
StraightLineFitter
public StraightLineFitter(double[] x, double[] y) Constructor.- Parameters:
x
- x coordinates of input data to be fitted to a straight line.y
- y coordinates of input data to be fitted to a straight line.- Throws:
IllegalArgumentException
- if provided arrays don't have the same length.
-
StraightLineFitter
public StraightLineFitter(double[] x, double[] y, double[] sig) Constructor.- Parameters:
x
- x coordinates of input data to be fitted to a straight line.y
- y coordinates of input data to be fitted to a straight line.sig
- standard deviation (i.e. errors) of provided data. This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.- Throws:
IllegalArgumentException
- if provided arrays don't have the same length.
-
-
Method Details
-
getX
public double[] getX()Returns array containing x coordinates of input data to be fitted to a straight line.- Returns:
- array containing x coordinates of input data to be fitted to a straight line.
-
getY
public double[] getY()Returns array containing y coordinates of input data to be fitted to a straight line.- Returns:
- array containing y coordinates of input data to be fitted to a straight line.
-
getSig
public double[] getSig()Returns standard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.- Returns:
- standard deviations of each pair of points (x,y).
-
setInputData
public final void setInputData(double[] x, double[] y) Sets input data to fit a straight line to.- Parameters:
x
- x coordinates.y
- y coordinates.- Throws:
IllegalArgumentException
- if arrays don't have the same length.
-
setInputDataAndStandardDeviations
public final void setInputDataAndStandardDeviations(double[] x, double[] y, double[] sig) Sets input data and standard deviations of input data to fit a straight line to.- Parameters:
x
- x coordinates.y
- y coordinates.sig
- standard deviations of each pair of points (x,y). This is optional, if not provided, variances of a and b will be estimated assuming equal error for all input points.- Throws:
IllegalArgumentException
- if arrays don't have the same length.
-
isReady
public boolean isReady()Indicates whether this instance is ready because enough input data has been provided to start the fitting process. -
getA
public double getA()Returns estimated "a" parameter of line following equation y = a + b*x- Returns:
- estimated "a" parameter.
-
getB
public double getB()Returns estimated "b" parameter of line following equation y = a + b*x- Returns:
- estimated "b" parameter
-
getSigA
public double getSigA()Returns estimated standard deviation of parameter "a".- Returns:
- estimated standard deviation of parameter "a".
-
getSigB
public double getSigB()Returns estimated standard deviation of parameter "b".- Returns:
- estimated standard deviation of parameter "b".
-
getChi2
public double getChi2()Returns estimated chi square value.- Returns:
- estimated chi square value.
-
getQ
public double getQ()Returns estimated goodness-of-fit probability (i.e. that the fit would have a chi square value equal or larger than the estimated one).- Returns:
- estimated goodness-of-fit probability.
-
getSigdat
public double getSigdat()Returns estimated standard deviation of provided input data. This is only estimated if array of standard deviations of input points is not provided.- Returns:
- estimated standard deviation of provided input data.
-
fit
Fits a straight line following equation y = a + b*x to provided data (x, y) so that parameters associated a, b can be estimated along with their variances, covariance and chi square value.- Specified by:
fit
in classFitter
- Throws:
FittingException
- if fitting fails.NotReadyException
- if enough input data has not yet been provided.
-
fitWithSig
Fits data when standard deviations of input data is provided.- Throws:
FittingException
- if fitting fails.
-
fitWithoutSig
private void fitWithoutSig()Fits data when standard deviations of input data is not provided.
-