STAT 306 - Module 10
In Module 09, we estimated \(\sigma^2\), the variance of the errors, with the residual mean square (also denoted \(MSE\)) \[ \hat\sigma^2 := MSE = \frac{\mathbf{e^\top e}}{n-(p+1)} = \frac{RSS}{n-(p+1)} \;, \] and promised to justify this choice.
Today, we’ll work towards understanding why this is the case.
Recall our linear model \[ \mathbf{Y} = \mathbf{X}\pmb{\beta} + \pmb{\varepsilon} \;, \] where \(\pmb{\varepsilon}\) is a vector containing the error terms \(\varepsilon_1,\dotsc,\varepsilon_n\), which are independent \(N(0,\sigma^2)\). In vector form, \(\pmb{\varepsilon}\sim N_n(\mathbf{0},\sigma^2\mathbf{I}_n)\), so \[ \mathbb{E}[\pmb{\varepsilon}] = \mathbf{0} := \begin{bmatrix} 0 \\ \vdots \\ 0 \end{bmatrix} \;, \qquad \mathrm{Cov}(\pmb{\varepsilon}) = \mathbb{E}[\pmb{\varepsilon}\pmb{\varepsilon}^\top] = \sigma^2\mathbf{I}_n \;. \] (Recall that \(\mathbf{I}_n\) is the \(n\times n\) identity matrix.)
Throughout, the first column of \(\mathbf{X}\) is a column of ones (the intercept), \(\mathbf{X}\) has full column rank \(p+1\) (so \(\mathbf{X^\top X}\) is invertible), and \(n > p+1\).
Our least squares estimates of the \(p+1\) model coefficients \(\pmb{\beta}\) are given by \[ \widehat{\pmb{\beta}} = (\mathbf{X^\top X})^{-1}\mathbf{X^\top y} \;, \] and our observed residuals are \[ \mathbf{e} = \mathbf{y} - \mathbf{X}\widehat{\pmb{\beta}} = \mathbf{y} - \hat{\mathbf{y}} \;. \]
The residual sum of squares is \[RSS = \mathbf{e^\top e} = \sum_{i=1}^n(y_i-\hat{y}_i)^2 \;. \]
Let’s now consider the residuals as a random vector \(\mathbf{E}=\mathbf{Y}-\mathbf{X}\widehat{\pmb{\beta}} = \mathbf{Y}-\widehat{\mathbf{Y}}\), where now \(\widehat{\pmb{\beta}} = (\mathbf{X^\top X})^{-1}\mathbf{X^\top Y}\) is the (random) estimator.
Which of the following correctly matches the variables to their definitions?
| \(\quad\mathbf{y}-\hat{\mathbf{y}}\quad\) | \(\quad\mathbf{Y} - \mathbf{X}\pmb{\beta}\quad\) | \(\quad\mathbf{Y}-\mathbf{X}\widehat{\pmb{\beta}}\quad\) | |
|---|---|---|---|
| (A) | \(\pmb{\varepsilon}\) | \(\mathbf{E}\) | \(\mathbf{e}\) |
| (B) | \(\pmb{\varepsilon}\) | \(\mathbf{e}\) | \(\mathbf{E}\) |
| (C) | \(\mathbf{E}\) | \(\pmb{\varepsilon}\) | \(\mathbf{e}\) |
| (D) | \(\mathbf{e}\) | \(\pmb{\varepsilon}\) | \(\mathbf{E}\) |
| (E) | \(\mathbf{e}\) | \(\mathbf{E}\) | \(\pmb{\varepsilon}\) |
Which of the following correctly matches the variables to their definitions?
| \(\quad\mathbf{y}-\hat{\mathbf{y}}\quad\) | \(\quad\mathbf{Y} - \mathbf{X}\pmb{\beta}\quad\) | \(\quad\mathbf{Y}-\mathbf{X}\widehat{\pmb{\beta}}\quad\) | |
|---|---|---|---|
| (A) | \(\pmb{\varepsilon}\) | \(\mathbf{E}\) | \(\mathbf{e}\) |
| (B) | \(\pmb{\varepsilon}\) | \(\mathbf{e}\) | \(\mathbf{E}\) |
| (C) | \(\mathbf{E}\) | \(\pmb{\varepsilon}\) | \(\mathbf{e}\) |
| (D) | \(\mathbf{e}\) | \(\pmb{\varepsilon}\) | \(\mathbf{E}\) |
| (E) | \(\mathbf{e}\) | \(\mathbf{E}\) | \(\pmb{\varepsilon}\) |
\[ \begin{align} \hat{\mathbf{y}} &= \mathbf{X}\widehat{\pmb{\beta}}\\ &= \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top y}\\ &= \mathbf{P}\mathbf{y} \end{align} \]
\[ \begin{align} \mathbf{P}\mathbf{P} &= \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top} \\ &= \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top}\\ &= \mathbf{P} \;. \end{align} \]
\[ \begin{align} \mathbf{P}^\top &= \left(\mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top}\right)^\top \\ &= \mathbf{X}\left[(\mathbf{X^\top X})^{-1}\right]^\top\mathbf{X^\top} \\ &= \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top}\\ &= \mathbf{P} \;. \end{align} \]
\[ \begin{align} \mathbf{E} &= \mathbf{Y} - \widehat{\mathbf{Y}} \\ &= \mathbf{Y} - \mathbf{P}\mathbf{Y} \\ &= (\mathbf{I}_n - \mathbf{P})\mathbf{Y} \\ &= (\mathbf{I}_n - \mathbf{P})(\mathbf{X}\pmb{\beta}+\pmb{\varepsilon}) \\ &= (\mathbf{I}_n - \mathbf{P})\mathbf{X}\pmb{\beta} + (\mathbf{I}_n - \mathbf{P})\pmb{\varepsilon} \;. \end{align} \]
Hint: Show that \((\mathbf{I}_n - \mathbf{P})\mathbf{X}\pmb{\beta} = \mathbf{0}\)
\[ \begin{align} (\mathbf{I}_n - \mathbf{P})\mathbf{X} &= (\mathbf{I}_n - \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X^\top})\mathbf{X} \\ &= \mathbf{X} - \mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X}^\top\mathbf{X}\\ &= \mathbf{X} - \mathbf{X}\\ &= \mathbf{0} \;. \end{align} \]
Therefore, \((\mathbf{I}_n - \mathbf{P})\mathbf{X}\pmb{\beta} = \mathbf{0}\pmb{\beta} = \mathbf{0}\).
Hence, \(\mathbf{E} = (\mathbf{I}_n - \mathbf{P})\pmb{\varepsilon}\).
Show that \(\mathbf{I}_n-\mathbf{P}\) is:
Which of the following is equal to \((\mathbf{I}_n-\mathbf{P})(\mathbf{I}_n-\mathbf{P})^\top\)?
Which of the following is equal to \((\mathbf{I}_n-\mathbf{P})(\mathbf{I}_n-\mathbf{P})^\top\)?
Symmetry: \[ \begin{align} (\mathbf{I}_n-\mathbf{P})^\top &= \mathbf{I}_n^\top - \mathbf{P}^\top \\ &= \mathbf{I}_n - \mathbf{P} \end{align} \]
Idempotency: \[ \begin{align} (\mathbf{I}_n-\mathbf{P})(\mathbf{I}_n-\mathbf{P}) &= \mathbf{I}_n - \mathbf{P} - \mathbf{P} + \mathbf{P}\mathbf{P} \\ &= \mathbf{I}_n - \mathbf{P} - \mathbf{P} + \mathbf{P} \\ &= \mathbf{I}_n - \mathbf{P} \end{align} \]
Therefore, \[ \begin{align} (\mathbf{I}_n-\mathbf{P})(\mathbf{I}_n-\mathbf{P})^\top &= (\mathbf{I}_n-\mathbf{P})(\mathbf{I}_n-\mathbf{P}) \\ &= \mathbf{I}_n-\mathbf{P} \end{align} \]
Show that the sum of the residuals is zero, i.e., \(\sum_{i=1}^n E_i = 0\).
Hint: Show that \(\mathbf{X}^\top\mathbf{E} = \mathbf{0}\), and recall that the first column of \(\mathbf{X}\) is a column of ones (due to the intercept).
Compute the expectation of the residuals, \(\mathbb{E}[\mathbf{E}]\).
What is the expectation of \(\mathbf{E}\)?
What is the expectation of \(\mathbf{E}\)?
Compute the expectation of the residuals, \(\mathbb{E}[\mathbf{E}]\).
Solution:
There are different ways to show this: \[\mathbb{E}[\mathbf{E}] = \mathbb{E}[\mathbf{Y}-\mathbf{X}\widehat{\pmb{\beta}}] = \mathbb{E}[\mathbf{Y}] - \mathbf{X}\mathbb{E}[\widehat{\pmb{\beta}}] = \mathbf{X}\pmb{\beta} - \mathbf{X}\pmb{\beta} = \mathbf{0}\]
Another way: \[\mathbb{E}[\mathbf{E}] = \mathbb{E}[(\mathbf{I}_n - \mathbf{P})\pmb{\varepsilon}] = (\mathbf{I}_n - \mathbf{P})\mathbb{E}[\pmb{\varepsilon}] = (\mathbf{I}_n - \mathbf{P})\mathbf{0} = \mathbf{0}\]
Compute the covariance matrix of the residuals, \(\mathrm{Cov}(\mathbf{E})\).
Which of the following is the covariance matrix of \(\mathbf{E}\)?
Which of the following is the covariance matrix of \(\mathbf{E}\)?
Compute the covariance matrix of the residuals, \(\mathrm{Cov}(\mathbf{E})\).
Solution:
Also, the residuals are, in general, correlated. For \(i \neq j\), \[\mathrm{Cov}(E_i, E_j) = -\sigma^2 P_{ij}\]
We will come back to this when we discuss leverage and standardized residuals.
The Residual Mean Square is given by \[ \hat{\sigma}^2 = \frac{\mathbf{E^\top E}}{n-(p+1)} \]
Compute \(\mathbb{E}\left[\hat{\sigma}^2\right]\).
Hints:
- For a vector \(\mathbf{x}\) and a matrix \(\mathbf{A}\), \(\mathbf{x}^\top \mathbf{A} \mathbf{x}\) is the matrix notation for a quadratic form, and \(\mathbf{x}^\top \mathbf{A} \mathbf{x} = \sum_{i} \sum_j x_ix_j A_{ij}\).
- \(\sum_i A_{ii}=\mathrm{tr}(\mathbf{A})\)
- For any matrices \(\mathbf{A}\), \(\mathbf{B}\), and \(\mathbf{C}\) of appropriate dimensions, we have \(\mathrm{tr}(\mathbf{ABC}) = \mathrm{tr}(\mathbf{BCA}) = \mathrm{tr}(\mathbf{CAB})\).
- For any matrices \(\mathbf{A}\) and \(\mathbf{B}\) of appropriate dimensions, we have \(\mathrm{tr}(\mathbf{A+B}) = \mathrm{tr}(\mathbf{A}) + \mathrm{tr}(\mathbf{B})\) and \(\mathrm{tr}(\mathbf{A-B}) = \mathrm{tr}(\mathbf{A}) - \mathrm{tr}(\mathbf{B})\).
Which of the following is equal to \(\mathbb{E}\left[\mathbf{E^\top E}\right]\)?
Which of the following is equal to \(\mathbb{E}\left[\mathbf{E^\top E}\right]\)?
Note that: \[ \begin{align*} \mathbb{E}\left[\sum_{i=1}^nE_i^2\right] &= \sum_{i=1}^n \mathbb{E}\left[E_i^2\right] \\ &= \sum_{i=1}^n Var(E_i) \quad \text{(since } \mathbb{E}[E_i] = 0) \\ &= \sum_{i=1}^n \sigma^2(1-P_{ii}) \\ &= \sigma^2\left(n-\sum_{i=1}^nP_{ii}\right) \\ &= \sigma^2\left(n-\text{tr}\left(\mathbf{P}\right)\right)\\ &= \sigma^2\left(n-\text{tr}\left(\mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X}^\top\right)\right) \\ &= \sigma^2\left(n-\text{tr}\left((\mathbf{X^\top X})^{-1}\mathbf{X}^\top\mathbf{X}\right)\right) \\ &= \sigma^2\left(n-\text{tr}\left(\mathbf{I}_{p+1}\right)\right) \\ &= \sigma^2\left(n-(p+1)\right) \end{align*} \]
Another way of showing this is to use the properties of the trace operator and the fact that \(\mathbf{E} = (\mathbf{I}_n-\mathbf{P})\pmb{\varepsilon}\): \[ \begin{align} \mathbb{E}\left[\mathbf{E^\top E}\right] &= \mathbb{E}\left[\left(\left(\mathbf{I}_n-\mathbf{P}\right)\pmb{\varepsilon}\right)^\top\left(\mathbf{I}_n-\mathbf{P}\right)\pmb{\varepsilon}\right] \\ &= \mathbb{E}\left[\pmb{\varepsilon}^\top\left(\mathbf{I}_n-\mathbf{P}\right)^\top\left(\mathbf{I}_n-\mathbf{P}\right)\pmb{\varepsilon}\right] \\ &= \mathbb{E}\left[\pmb{\varepsilon}^\top\left(\mathbf{I}_n-\mathbf{P}\right)\pmb{\varepsilon}\right]\quad \scriptsize{\text{call } \mathbf{M}=\mathbf{I}_n-\mathbf{P}}\\ &= \mathbb{E}\left[\pmb{\varepsilon}^\top\mathbf{M}\pmb{\varepsilon}\right] \\ &= \mathbb{E}\left[\sum_{i=1}^n\sum_{j=1}^n\varepsilon_i\varepsilon_j M_{ij}\right] \\ &= \sum_{i=1}^n\sum_{j=1}^nE\left[\varepsilon_i\varepsilon_j\right] M_{ij} \scriptsize{\qquad \text{since } \mathbb{E}[\varepsilon_i\varepsilon_j]=\mathrm{Cov}(\varepsilon_i,\varepsilon_j)=0 \text{ for } i\neq j}\\ &= \sum_{i=1}^nE\left[\varepsilon_i^2\right] M_{ii} \\ &= \sum_{i=1}^n\sigma^2 M_{ii} \\ &= \sigma^2\sum_{i=1}^n M_{ii} \\ &= \sigma^2 \mathrm{tr}\left(\mathbf{M}\right) \\ &= \sigma^2 \mathrm{tr}\left(\mathbf{I}_n-\mathbf{P}\right)\\ &= \sigma^2\left(\mathrm{tr}\left(\mathbf{I}_n\right) - \mathrm{tr}\left(\mathbf{P}\right)\right) \\ &= \sigma^2\left(\mathrm{tr}\left(\mathbf{I}_n\right) - \mathrm{tr}\left(\mathbf{X}(\mathbf{X^\top X})^{-1}\mathbf{X}^\top\right)\right) \\ &= \sigma^2\left(n - \mathrm{tr}\left((\mathbf{X^\top X})^{-1}\mathbf{X}^\top\mathbf{X}\right)\right) \\ &= \sigma^2\left(n - \mathrm{tr}\left(\mathbf{I}_{p+1}\right)\right) \\ &= \sigma^2\left(n-(p+1)\right) \end{align} \]
This shows that the residual mean square is an unbiased estimator of \(\sigma^2\).
© 2025 Rodolfo Lourenzutti – Material Licensed under CC By-SA 4.0