2.2 Least squares

For any candidate line \(a + bX\), the residuals are \(e_i = Y_i - a - bX_i\). The least squares estimates minimise the residual sum of squares \[ S(a, b) = \sum _{i=1}^n (Y_i - a - bX_i)^2 . \]

Theorem 2.2.1. Under (A4), \(S\) has a unique minimum at \begin {equation} \label {eq:ols2} b = \frac {\sum x_i y_i}{\sum x_i^2}, \qquad a = \bar Y - b\bar X , \end {equation} where \(x_i = X_i - \bar X\) and \(y_i = Y_i - \bar Y\).

Proof. Setting the partial derivatives to zero gives the normal equations \begin {align*} \frac {\partial S}{\partial a} &= -2\sum (Y_i - a - bX_i) = 0 ,\\ \frac {\partial S}{\partial b} &= -2\sum X_i(Y_i - a - bX_i) = 0 , \end {align*}

that is, \begin {align*} \sum Y_i &= na + b\sum X_i ,\\ \sum X_iY_i &= a\sum X_i + b\sum X_i^2 . \end {align*}

The first gives \(a = \bar Y - b\bar X\). Substituting into the second and using \(\sum X_iY_i - n\bar X\bar Y = \sum x_iy_i\) and \(\sum X_i^2 - n\bar X^2 = \sum x_i^2\) gives \(b\sum x_i^2 = \sum x_iy_i\). Under (A4) this has the unique solution (2.1).

The point is a minimum because \(S\) is a convex quadratic: its Hessian is \[ 2\begin {pmatrix} n & \sum X_i \\ \sum X_i & \sum X_i^2 \end {pmatrix}, \] with positive diagonal and determinant \(4\bigl (n\sum X_i^2 - (\sum X_i)^2\bigr ) = 4n\sum x_i^2 > 0\). □

The fitted values are \(\hat Y_i = a + bX_i\) and the residuals \(e_i = Y_i - \hat Y_i\). The normal equations are statements about the residuals, and they give the residuals four properties that are used constantly.

Theorem 2.2.2. The least squares residuals satisfy

(i)
\(\sum e_i = 0\), so the residuals have mean zero and \(\bar {\hat Y} = \bar Y\);
(ii)
\(\sum X_i e_i = 0\) and \(\sum x_i e_i = 0\): the residuals are uncorrelated with the regressor in the sample;
(iii)
\(\sum \hat Y_i e_i = 0\): the residuals are uncorrelated with the fitted values;
(iv)
the fitted line passes through the point of means \((\bar X, \bar Y)\).

Proof. (i) and the first part of (ii) are the two normal equations. Then \(\sum x_ie_i = \sum X_ie_i - \bar X\sum e_i = 0\). (iii) \(\sum \hat Y_ie_i = a\sum e_i + b\sum X_ie_i = 0\). (iv) is \(a = \bar Y - b\bar X\). □

These are the sample versions of \(E(v) = 0\) and \(\Cov (X, v) = 0\) for the best linear predictor in Theorem 1.4.4. Least squares imposes on the sample exactly the conditions that define the population best linear predictor, which is why it estimates it. That idea, “impose the sample version of a population moment condition”, is the method of moments, and it returns in full generality with GMM.

The decomposition of the sum of squares

In deviation form \(\hat y_i = \hat Y_i - \bar Y = bx_i\), and \(y_i = \hat y_i + e_i\).

Theorem 2.2.3. \[ \underbrace {\sum y_i^2}_{\text {TSS}} = \underbrace {\sum \hat y_i^2}_{\text {ESS}} + \underbrace {\sum e_i^2}_{\text {RSS}}, \qquad \text {with}\qquad \text {ESS} = b^2\sum x_i^2 = b\sum x_iy_i . \]

Proof. Square \(y_i = bx_i + e_i\) and sum: \(\sum y_i^2 = b^2\sum x_i^2 + 2b\sum x_ie_i + \sum e_i^2\). The middle term is zero by Theorem 2.2.2(ii). Finally \(b^2\sum x_i^2 = b\sum x_iy_i\) by (2.1). □

The total variation in \(Y\) about its mean splits into a part explained by the regression and a residual part. The proportion explained is the coefficient of determination \[ R^2 = \frac {\text {ESS}}{\text {TSS}} = 1 - \frac {\text {RSS}}{\text {TSS}}, \qquad 0 \leq R^2 \leq 1 . \]

Theorem 2.2.4. In the two-variable model \(R^2 = r^2\), the square of the sample correlation of \(X\) and \(Y\).

Proof. \(R^2 = \dfrac {b\sum x_iy_i}{\sum y_i^2} = \dfrac {(\sum x_iy_i)^2}{\sum x_i^2\sum y_i^2} = r^2\). □

Example 2.2.5. Five households report monthly income \(X\) (thousands of kwacha) and monthly food expenditure \(Y\) (hundreds of kwacha):

\(X_i\) 2 4 6 8 10
\(Y_i\) 3 4 6 6 9

Here \(\bar X = 6\) and \(\bar Y = 5.6\). The deviations are \[ x = (-4, -2, 0, 2, 4), \qquad y = (-2.6, -1.6, 0.4, 0.4, 3.4), \] so \begin {gather*} \sum x_i^2 = 40, \qquad \sum y_i^2 = 21.2,\\ \sum x_iy_i = 10.4 + 3.2 + 0 + 0.8 + 13.6 = 28 . \end {gather*} Hence \[ b = \frac {28}{40} = 0.7, \qquad a = 5.6 - 0.7(6) = 1.4 . \] Each extra K1 000 of income is associated with K70 more food spending: the marginal propensity to spend on food is \(0.07\), once the units are allowed for. The fitted values are \(2.8, 4.2, 5.6, 7.0, 8.4\), and the residuals are \[ e = (0.2,\ -0.2,\ 0.4,\ -1.0,\ 0.6), \] which sum to zero, and \(\sum x_ie_i = -0.8 + 0.4 + 0 - 2.0 + 2.4 = 0\), as Theorem 2.2.2 requires. The sums of squares are \[ \text {RSS} = 0.04 + 0.04 + 0.16 + 1 + 0.36 = 1.6, \qquad \text {ESS} = 0.7 \times 28 = 19.6, \qquad \text {TSS} = 21.2 , \] and \(R^2 = 19.6/21.2 = 0.9245\). Income accounts for about \(92\%\) of the variation in food spending in this small sample.

Questions on this section

Stuck on something here? Ask below and it stays attached to this topic.