Example Code

Understanding the Residue Output of the Linear Fit VI Using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This example is designed to explain the differences in the residue output values of the Linear Fit VI whenever the method used is changed between the "Least Square", "Least Absolute Residual", and "Bisquare" methods.


Description
When using the Linear Fit VI, you can select between the aforementioned methods to change how the line-of-best-fit is calculated. Alongside this, the method for which the residual error is calculated is also changed. When using another program to calculate the best fit line, such as Excel, you will also obtain residue values. However, it may not always be clear how these values compare to the values obtained in LabVIEW if you aren't sure the method used.

Below is the Context Help description for the residues output of the Linear Fit VI.

Residues Context Help 2.png

The description mentions that the residue is calculated by either the "mean absolute error" or the "mean square error". The equations for both are shown below:

Mean Square Error.png

 

Mean Absolute Error.png

The example VI below shows manual calculations that demonstrate when each type of residue equation is used.


Requirements

  • LabVIEW 2012 (or compatible)


Steps to Implement or Execute Code

  1. Run the VI and switch the method to see how the different Residue calculations compare to the residue output of the Linear Fit VI.
  2. The X and Y arrays are constants that can be replaced with other X and Y-value pairs, if needed.

 

Additional Information or References
VI Block Diagram

1.png 

 

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Ryan P.
CLA

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.