WebCab Probability and Statistics for COM v3.6

GeneralLinear.SetGeneralFit Method 

Evaluates the greatest likelihood coefficients of the function of best fit in accordance with the least squares approach for the function basis given (i.e. fitting the function).

public double[] SetGeneralFit(
   double[] xDataPoints,
   double[] yDataPoints,
   double[] sigma,
   double[] initialValue,
   bool[] fit
);

Parameters

xDataPoints
An array where the k-th term corresponds to the x-axis coordinate value of the k-th data element of the data set from which the (weighted or not) function of best fit is fitted.
yDataPoints
An array where the k-th term corresponds to the y-axis coordinate value of the k-th data element of the data set from which the (weighted or not) function of best fit is fitted.
sigma
An array where the k-th term depending on your point of view is one of the following:
  1. Standard Fitting: If you do not wish to take the measurement errors or weight the data points then all the elements of the array can be set to 0.0, where the array has a length equal to the number of data points considered.
  2. Measurement Error Fitting: is the standard deviation of the value in the y-axis of the k-th data point within the experimental data set.
  3. Weighted Fitting: is inverse of the weight given to the k-th data point.
.
initialValue
An array where the k-th term corresponds the initial estimate of the value of the k-th coefficient within the function of best fit (i.e. ak above).
fit
An array of booleans where the k-th term is a true boolean if the k-th coefficient is fitted to the data set considered, and is a false boolean if the k-th coefficient is not fitted to the data set considered and held fixed. Please note that if a coefficient is held fixed then its value within the best fit function will correspond to the initialValue parameter value provided.

Return Value

Returns an array of doubles where the k-th term corresponds to the value of the k-th coefficient (i.e. ak) within the function of best fit.

Remarks

Further Details

In the simplest case this method given a data set (xi, yi), for i=0,...,m, finds the coefficients a1,...,an such that the function:

f(x) = a1 * f1(x) + a2 * f2(x) + ... + an * fn(x)

where f1,...,fn are the function basis set using SetFunctionBasis, is the function of best fit in accordance with the least square approach for the data set considered. That is, the coefficients are selected in such a way that the points (xi, f(xi)), for i=1,...,m; are a best fit in accordance with the least squares approach for the given data set (xi, yi), i=1,...,m.

Fixing some Coefficients

Please note that within this implementation we reserve the right to fix some of the coefficients of the function of best fit before the function is fitted. In such instances the above described fitting is performed with some of the coefficients fixed to the initial value which are given as parameters. The fit parameter is used in order to determine which (if any) of the coefficients are kept fixed during the fitting.

Measurement Errors, Weighted Best Fit and the Sigma Parameter

As mentioned within the overview of this class (see GeneralLinear) you are able to incorporate the following features when determining the regression model by offering three differing interpretations of the parameter sigma, as detailed below:

  1. Standard Best Fit: If you do not wish to take the measurement errors or weight the data points then all the elements of the parameter array sigma should be set to 1.0. In terms of the values of the model parameters of the fitted regression model the measurement errors could have been set to any strictly positive number however in doing so the Chi-Squared measure of the fit would have been scaled by a factor 1/sigma2, in accordance with the definition of Chi-Squared measure.
  2. Measurement Errors: You are able to find the greatest likelihood coefficients when the measurement errors (i.e. the standard deviations of the errors of the observations in the yi's) are taken into account. In order to fit the function taking into account the measurement errors you are required to provide the k-th term of the parameter sigma for the measurement error of the yk (i.e. the value of the y-axis coordinate of the k-th data point) which is then used within the fitting of the function. Note that all the measurement errors must be strictly positive numbers.
  3. Weighted Best Fit: If you wish you are also able to apply this class with the view of finding the best weighted fit where the 1/sigmai corresponds to the (relative) weight applied to the i-th data point. That is, as sigmai increase the data point is given a correspondingly lower weight.

Note: Within the class MeasurementErrors we offer the auxiliary method MeasurementError which evaluates the measurement error of a collection of measurements of an experiment in the same state.

Exceptions

Exception TypeCondition
ThrownThrown if any of the elements of the parameter sigma are not strictly positive numbers. The reason why such a possibility must be excluded is because it would imply a term of the Chi-Squared measure involving division by zero.

See Also

GeneralLinear Class | WebCab.COM.Statistics.CurveFitting Namespace