Skip to main content

Subsubsection Scalar Arithmetic Notation & Derivation

Definition A.2.3 Line of Best Fit.

Given data vectors \(\vec{x}=\left(x_1, \dots, x_n\right)\) and \(\vec{y}=\left(y_1, \dots, y_n\right)\text{,}\) we seek the line of best fit:
\begin{equation*} y=mx+b \, . \end{equation*}
The following derivation of this line is visualized below as a single โ€™logical chainโ€™ of matrix operations:
\begin{equation*} \underbrace{ \begin{bmatrix} x_1 & x_2 & \dots & x_n \\ 1 & 1 & \dots & 1 \\ \end{bmatrix} \begin{bmatrix} x_1 & 1 \\ x_2 & 1 \\ \vdots & \vdots \\ x_n & 1 \end{bmatrix} }_{ \begin{bmatrix} s_2 & s_1 \\ s_1 & n \end{bmatrix} } \begin{bmatrix} m \\ b \end{bmatrix} = \underbrace{ \begin{bmatrix} x_1 & x_2 & \dots & x_n \\ 1 & 1 & \dots & 1 \end{bmatrix} \begin{bmatrix} y_1 \\ y_2 \\ \vdots \\ y_n \end{bmatrix} }_{ \begin{bmatrix} c_{xy} \\ c_y \end{bmatrix} } \, . \end{equation*}
Here, the scalar sums are defined as:
\begin{equation*} s_1 = \sum_{i=1}^n x_i \, , \quad s_2 = \sum_{i=1}^n x_i^2 \, , \quad c_{xy} = \sum_{i=1}^n x_i y_i \, , \quad c_y = \sum_{i=1}^n y_i \end{equation*}