Least Squares &
Normal Equations
Master the foundation of regression analysis: find the best-fit line by minimizing the sum of squared residuals and derive the closed-form solution via the normal equations.
What Is Least Squares Estimation?
Given a set of data points \((x_1,y_1),\ldots,(x_n,y_n)\), we want to find a linear model \(\hat{y} = \beta_0 + \beta_1 x\) that best fits the data. But what does "best" mean?
A residual \(e_i = y_i - \hat{y}_i\) is the vertical distance between an observed value and the fitted value. Squaring ensures all errors are positive and penalizes large deviations heavily.
Visualizing Residuals
Why Squared Errors?
The Matrix Formulation
We rewrite the linear model \(y = X\beta + \varepsilon\) in matrix form. For \(n\) observations and \(p\) parameters (e.g., an intercept and \(p-1\) predictors):
The objective becomes minimizing the scalar quantity:
Deriving the Normal Equations
Geometric Interpretation
OLS vs. GLS
| Ordinary Least Squares | Generalized Least Squares | |
|---|---|---|
| Assumption | \(\operatorname{Cov}(\boldsymbol{\varepsilon}) = \sigma^2 \mathbf{I}\) | \(\operatorname{Cov}(\boldsymbol{\varepsilon}) = \sigma^2 \boldsymbol{\Omega}\) |
| Estimator | \((\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}\) | \((\mathbf{X}^T\boldsymbol{\Omega}^{-1}\mathbf{X})^{-1}\mathbf{X}^T\boldsymbol{\Omega}^{-1}\mathbf{y}\) |
| Error structure | Homoscedastic, uncorrelated | Heteroscedastic and/or correlated |
| When to use | Default: errors are iid | When error covariance is known |
How to Apply the Normal Equations
Example 1: Simple Linear Regression
Data: \((1,2),\;(2,3),\;(3,5)\). Fit \(\hat{y} = \beta_0 + \beta_1 x\).
Example 1: Fitted Line
Example 2: Multiple Regression
Data with two predictors \(x_1, x_2\). Three observations:
| Obs | \(x_1\) | \(x_2\) | \(y\) |
|---|---|---|---|
| 1 | 1 | 0 | 1 |
| 2 | 0 | 1 | 2 |
| 3 | 1 | 1 | 4 |
Example 2: Solution
Solving \(\mathbf{X}^T\mathbf{X}\hat{\boldsymbol{\beta}} = \mathbf{X}^T\mathbf{y}\):
Properties of \(\hat{\boldsymbol{\beta}}\)
Common Mistakes
Summary of Key Formulas
| Concept | Formula | Dimensions |
|---|---|---|
| Objective | \(\min_{\boldsymbol{\beta}} \|\mathbf{y} - \mathbf{X}\boldsymbol{\beta}\|^2\) | Scalar |
| Normal equations | \(\mathbf{X}^T\mathbf{X}\hat{\boldsymbol{\beta}} = \mathbf{X}^T\mathbf{y}\) | \(p \times p\) system |
| OLS estimator | \(\hat{\boldsymbol{\beta}} = (\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\mathbf{y}\) | \(p \times 1\) |
| Hat matrix | \(\mathbf{H} = \mathbf{X}(\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\) | \(n \times n\) |
| Residuals | \(\mathbf{e} = (\mathbf{I} - \mathbf{H})\mathbf{y}\) | \(n \times 1\) |
| Variance of \(\hat{\boldsymbol{\beta}}\) | \(\sigma^2(\mathbf{X}^T\mathbf{X})^{-1}\) | \(p \times p\) |
Question 1 of 5
The normal equations are given by \(\mathbf{X}^T\mathbf{X}\hat{\boldsymbol{\beta}} = \mathbf{X}^T\mathbf{y}\). What condition on \(\mathbf{X}\) guarantees a unique solution?
Question 2 of 5
In the geometric interpretation of least squares, the residual vector \(\mathbf{e}\) is:
Question 3 of 5
Given \(\mathbf{X}^T\mathbf{X} = \begin{pmatrix} 4 & 2 \\ 2 & 2 \end{pmatrix}\) and \(\mathbf{X}^T\mathbf{y} = \begin{pmatrix} 6 \\ 4 \end{pmatrix}\), what is \(\hat{\boldsymbol{\beta}}\)?
Question 4 of 5
The Gauss-Markov Theorem states that under standard assumptions, the OLS estimator is BLUE. What does BLUE stand for?
Question 5 of 5
The hat matrix \(\mathbf{H} = \mathbf{X}(\mathbf{X}^T\mathbf{X})^{-1}\mathbf{X}^T\) projects \(\mathbf{y}\) onto the column space of \(\mathbf{X}\). Which property does \(\mathbf{H}\) not possess?