Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Linear Fit (Not in Base Package)

LabVIEW 8.5 Help
August 2007

NI Part Number:
371361D-01

»View Product Info

Returns the linear fit of a data set (X, Y) using the Least Square, Least Absolute Residual, or Bisquare method.

Details  Examples

Y is the array of dependent values. Y must contain at least two points.
X is the array of independent values. X must be the same size as Y.
Weight is the array of weights for the observations (X, Y). Weight must be the same size as Y. If Weight is unwired, this VI sets all elements of Weight to 1.

If an element in Weight is less than 0, this VI uses the absolute value of the element.
tolerance determines when to stop the iterative adjustment of slope and intercept when you use the Least Absolute Residual or Bisquare method. If the relative difference of residue in two successive iterations is less than tolerance, this VI returns the resulting slope and intercept.

If tolerance is less than or equal to 0, this VI sets tolerance to 0.0001.
method specifies the fitting method. The default is Least Square.

0Least Square (default)
1Least Absolute Residual
2Bisquare
Best Linear Fit returns the y-values of the fitted model.
slope returns the slope of the fitted model.
intercept returns the intercept of the fitted model.
error returns any error or warning from the VI. You can wire error to the Error Cluster From Error Code VI to convert the error code or warning into an error cluster.
residue returns the weighted mean error of the fitted model. If method is Least Absolute Residual, residue is the weighted mean absolute error. Otherwise, residue is the weighted mean square error.

Linear Fit Details

This VI fits experimental data to a straight line of the general form described by the following equation:

f = ax + b

where x is the input sequence X, a is the slope, and b is the intercept. This VI finds a and b that best fit the observations (X, Y).

If the noise of Y is Gaussian distributed, use the Least Square method. The following figure illustrates the linear fit result using this method.

When the fitting method is Least Square, this VI finds the slope and intercept of the linear model by minimizing the residue according to the following equation:

where N is the length of Y, wi is the ith element of Weight, fi is the ith element of Best Linear Fit, and yi is the ith element of Y.

The Least Absolute Residual and Bisquare fitting methods are robust fitting methods. Use these methods if outliers in the observations exist. The following figure compares the fit results of the Least Square, Least Absolute Residual, and Bisquare fitting methods. In most cases, the Bisquare method is less sensitive to outliers than the Least Absolute Residual method.

When the fitting method is Least Absolute Residual, this VI finds the slope and intercept of the linear model by minimizing the residue according to the following equation:

.

When the fitting method is Bisquare, this VI obtains the slope and intercept using an iterative process, as shown in the following flowchart, and calculates the residue using the same formula as in the Least Square method.

Examples

Refer to the following VIs for examples of using the Linear Fit VI:

  • Regression Solver VI: labview\examples\analysis\regressn.llb
  • Regressions Demo VI: labview\examples\analysis\regressn.llb
  • Financial Forecasting VI: labview\examples\analysis\regressn.llb
  • Linear, Exp, and Power Fitting VI: labview\examples\math\curvefit.llb
  • Parametric Curve Fitting VI: labview\examples\math\curvefit.llb
  • Robust linear fit VI: labview\examples\math\curvefit.llb

Resources


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit