Linear algebra: best fit line: method of least squares by hand

The tutor shows a nice trick to obtain a least squares line using matrix algebra.

In my Nov 25 post I mentioned how, with Excel or LibreOffice Calc, to get a best-fit line for

x y
0 3
2 5
6 10
8 12

The same line can be gotten by hand, with the following ideas:

  1. Imagining the best fit line to be of form y=mx+b, the table above can be related as the matrix equation
  2. We multiply each side by the transpose matrix:
  3. Performing the multiplication on each side yields
  4. which means

    Solving, we get m=1.15, b=2.9: our best-fit line is y=1.15x + 2.9, same with the result from November 25 using a spreadsheet.

    Neat, eh?

    Source:

    Johnson/Riess/Arnold. Introduction to Linear Algebra, Second Ed. Don Mills: Addison-Wesley, 1989.

    Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply