Skip to content

Math 141 · Lesson 22

Least Squares Line

Fit a line by hand to a dataset and track the length of the residual vector as the line moves. Then compare the drawn line with the least squares line.

Lesson 22: The Method of Least Squares I

About this tool

The residual of each data point is drawn on the scatter plot, with a magnified residual plot below it. Show numbers works out the residual vector:

r‾=y‾−(mx‾+b1‾).\overline{r} = \overline{y} - (m\overline{x} + b\overline{1}).

The panel also tracks the length ∥r‾∥\lVert \overline{r} \rVert and the root mean square error (RMSE). The RMSE is ∥r‾∥/n\lVert \overline{r} \rVert / \sqrt{n} for nn data points. Least squares moves the drawn line to the least squares line. Show least squares line draws the least squares line dashed for comparison and lists its ∥r‾∥\lVert \overline{r} \rVert and RMSE.

Under More:

  • Line comparison. Save this line adds the current line to a table of ∥r‾∥\lVert \overline{r} \rVert and RMSE. A row loads its line again.
  • Squared residuals. Show squares draws the square of each residual. The total area of the squares is ∥r‾∥2\lVert \overline{r} \rVert^2.

The datasets are Twitter users, three points, US e-commerce sales and world population growth.