Advanced Analysis Library Only
AnalysisLibErrType LinearFitEx (double arrayX[], double arrayY[], double weight[], int numberOfElements, int fitMethod, double tolerance, double fittedData[], double *slope, double *intercept, double *residue);
Fits the data set (x, y) to the linear model using the Least Square, Least Absolute Residual, or Bisquare method. The following equation represents the linear model:
where | f represents the fittedData |
a is the slope | |
x represents the input sequence arrayX | |
b is the intercept |
where | n is numberOfElements |
wi is the i-th element of weight | |
fi is the i-th element of fittedData | |
yi is the i-th element of arrayY |
If fitMethod is BISQUARE, the function finds slope and intercept of the linear model by using reweighted least square fitting iteratively, as shown in the following flowchart:
Input | ||
Name | Type | Description |
arrayX | double-precision array | The x value of the data set (x, y). |
arrayY | double-precision array | The y value of the data set (x, y). If fittedData is NULL, arrayY is overwritten by the best fitted array. |
weight | double-precision array | The weight of each data point. If weight is NULL, the function sets all the elements of weight to 1. |
numberOfElements | integer | The length of arrayX, arrayY, and weight. |
fitMethod | integer | The fitting method. fitMethod must be one of the following values:
|
tolerance | double-precision | The stop criteria used in the Least Absolute Residual method or Bisquare method. In these two methods, the function adjusts the slope and intercept iteratively. If the relative difference of residue in two successive iterations is less than tolerance, the function returns the resulting slope and intercept. If tolerance is less than or equal to 0, the function sets tolerance to 0.0001. |
Output | ||
Name | Type | Description |
fittedData | double-precision array | The y values calculated using the fitted linear model. If fittedData is NULL, the best fit array overwrites arrayY. |
slope | double-precision | The slope of the fitted linear model. |
intercept | double-precision | The intercept of the fitted linear model. |
residue | double-precision | The weighted mean error of the linear fit. If fitMethod is LEAST_ABSOLUTE_RESIDUAL, residue is the weighted mean absolute error, as follows:
If fitMethod is LEAST_SQUARE or BISQUARE, residue is the weighted mean square error, as follows:
|
Name | Type | Description |
status | AnalysisLibErrType | A value that specifies the type of error that occurred. Refer to analysis.h for definitions of these constants. |