Wolfram Research

Function Repository Resource:

LeastSquaresPlot (1.0.0) current version: 1.0.1 »

Source Notebook

Plot data together with a visualization of the squared errors compared to a fit

Contributed by: Jon McLoone

ResourceFunction["LeastSquaresPlot"][data]

plots data together with the linear best fit and the squared errors.

ResourceFunction["LeastSquaresPlot"][data,n]

uses the order-n best fit.

ResourceFunction["LeastSquaresPlot"][data,expr,var]

also plots the curve given by expr and the variable var.

Details and Options

All ListPlot options are supported.
"SquareStyle" controls the style of the error squares.

Examples

Basic Examples (3) 

Show the squared errors of a linear fit to some data. A tooltip on each square gives its area:

In[1]:=
ResourceFunction["LeastSquaresPlot"][{1, 1, 2, 2, 3, 5}]
Out[1]=

Show the squared errors of a quadratic fit to some data. A tooltip on each square gives its area:

In[2]:=
ResourceFunction["LeastSquaresPlot"][{1, 1, 2, 2, 3, 5}, 2]
Out[2]=

Compare the errors to the parabola y=x2/10:

In[3]:=
ResourceFunction["LeastSquaresPlot"][{1, 1, 2, 2, 3, 5}, x^2/10, x]
Out[3]=

Options (1) 

All options for ListPlot are supported, along with an option "SquareStyle" to control the error squares:

In[4]:=
ResourceFunction["LeastSquaresPlot"][{1, 1, 2, 2, 3, 5}, "SquareStyle" -> Green]
Out[4]=

Publisher

Jon McLoone

Version History

  • 1.0.1 – 13 February 2023
  • 1.0.0 – 27 March 2020

Related Resources

License Information