STAT 306 - Module 08
What are the least squares estimators and their properties?
What changes in the interpretation of such models, or when making inference/predictions with them?
Confidence intervals and hypothesis tests for the parameters.
Prediction intervals for future observations.
Model diagnostics.
Suppose we want to explain \(Y\) using \(p\) covariates \(X_1, \ldots, X_p\).
The model generalizes very naturally to: \[ Y_i = \beta_0 + \beta_1X_{i1} + \cdots + \beta_pX_{ip} + \varepsilon_i \;,\quad i=1,\ldots,n \;, \]
\[ \mathbf{Y} = \begin{bmatrix} Y_1 \\ Y_2 \\ \vdots \\ Y_n \end{bmatrix}_{n \times 1} \;, \ \mathbf{X} = \begin{bmatrix} 1 & x_{11} & x_{12} & \cdots & x_{1p} \\ 1 & x_{21} & x_{22} & \cdots & x_{2p} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & x_{n1} & x_{n2} & \cdots & x_{np} \end{bmatrix}_{n \times (p+1)} \;, \\ \pmb{\beta} = \begin{bmatrix} \beta_0 \\ \beta_1 \\ \vdots \\ \beta_p \end{bmatrix}_{(p+1) \times 1} \;, \ \pmb{\varepsilon} = \begin{bmatrix} \varepsilon_1 \\ \varepsilon_2 \\ \vdots \\ \varepsilon_n \end{bmatrix}_{n \times 1} \;. \]
Which of the following models is a linear model?
Which of the following models is a linear model?
Note that if we have more than one covariate (i.e., \(p>1\)), then \((X_1,\dots,X_p,Y)\) lives in a \((p+1)\)-dimensional space.
We don’t have a line anymore: the regression surface is a \(p\)-dimensional hyperplane inside that \((p+1)\)-dimensional space.
To fit the model \(\mathbf{Y} = \mathbf{X}\pmb{\beta} + \pmb{\varepsilon}\) we minimize the residual sum of squares \(RSS(\mathbf{b}) = \sum_{i=1}^n e_i^2\), which can be written as
To fit the model \(\mathbf{Y} = \mathbf{X}\pmb{\beta} + \pmb{\varepsilon}\) we minimize the residual sum of squares \(RSS(\mathbf{b}) = \sum_{i=1}^n e_i^2\), which can be written as
For SLR, since we had only two coefficients, we used the estimator of the variance of the errors \[ \hat{\sigma}^2 = \frac{RSS}{n-2} \]
For MLR, since we have \(p+1\) coefficients, we use \[ \hat{\sigma}^2 = \frac{RSS}{n-(p+1)} \]
Let \(\mathbf{a}\) and \(\mathbf{y}\) be two \(p\)-dimensional vectors.
Minimize the \(RSS(\mathbf{b}) = \mathbf{e}^\top\mathbf{e}\) to obtain the least squares estimator \(\widehat{\pmb{\beta}}\) of the coefficients \(\pmb{\beta}\).
\[ \begin{align} RSS(\mathbf{b}) &= \mathbf{e}^\top\mathbf{e}\\ &= (\mathbf{Y} - \mathbf{X}\mathbf{b})^\top(\mathbf{Y} - \mathbf{X}\mathbf{b}) \\ &= \mathbf{b}^\top\mathbf{X}^\top\mathbf{X}\mathbf{b} - \mathbf{b}^\top\mathbf{X}^\top\mathbf{Y} - \mathbf{Y}^\top\mathbf{X}\mathbf{b} + \mathbf{Y}^\top\mathbf{Y} \\ &= \mathbf{b}^\top\mathbf{X}^\top\mathbf{X}\mathbf{b} - 2\mathbf{b}^\top\mathbf{X}^\top\mathbf{Y} + \mathbf{Y}^\top\mathbf{Y} \end{align} \]
\[ \frac{\partial RSS(\mathbf{b})}{\partial \mathbf{b}} = 2\mathbf{X}^\top\mathbf{X}\mathbf{b} - 2\mathbf{X}^\top\mathbf{Y} \]
Setting it to zero, we get \[ \begin{align} 2\mathbf{X}^\top\mathbf{X}\widehat{\pmb{\beta}} - 2\mathbf{X}^\top\mathbf{Y} &= 0\\ \mathbf{X}^\top\mathbf{X}\widehat{\pmb{\beta}} &= \mathbf{X}^\top\mathbf{Y} \end{align} \] which has the same form as the normal equation we obtained for simple linear regression.
If \(\mathbf{X}^\top\mathbf{X}\) is invertible, the unique least squares estimator is: \[ \widehat{\pmb{\beta}} = (\mathbf{X}^\top\mathbf{X})^{-1}\mathbf{X}^\top\mathbf{Y} \;. \]
For a multiple linear regression model with \(p\) covariates, the design matrix \(\mathbf{X}\) is of dimension \(n \times (p+1)\).
The \((p+1) \times (p+1)\) matrix \(\mathbf{X}^\top\mathbf{X}\) is invertible if and only if \(\mathbf{X}\) has full column rank: \[ \operatorname{rank}(\mathbf{X}) = p+1 \]
Suppose we want to explain penguins’ body mass not only by their flipper length but also by their bill length. Our linear model is then
\[ Y_i = \beta_0 + \beta_1x_{i1} +\beta_2x_{i2} +\varepsilon_i \;, \qquad \varepsilon_i\sim N(0,\sigma^2) \;. \]
Construct the design matrix \(\mathbf{X}\) by completing the partial R code below. Which of the following R functions will you need to use to do so?
c()rbind()cbind()data.frame()Tip
Use cbind() to combine an intercept column of ones with x1 and x2.
Some commands you’ll need to compute the least squares estimate \(\widehat{\pmb{\beta}}\):
The function t(A) computes the matrix transpose \(\mathbf{A}^\top\).
The operator A %*% B computes the matrix product \(\mathbf{AB}\).
The function solve(A,b) computes the vector c such that \(\mathbf{Ac=b}\).
Given the above, compute the least squares estimate
\[ \widehat{\pmb{\beta}} = (\mathbf{X}^\top\mathbf{X})^{-1}\mathbf{X}^\top\mathbf{y} \;. \]
Tip
Use t() for transposes, %*% for matrix multiplication, and solve() to solve the normal equations. Store your estimate in beta_hat.
What is the least squares estimate of the coefficient parameter for bill_length_mm?
What is the least squares estimate of the coefficient parameter for bill_length_mm?
lm() and separate the covariates on the right-hand side of the formula with +.\[ \widehat{\text{body mass}} = -5836.30 + 48.89\,(\text{flipper length}) + 4.96\,(\text{bill length}). \]
Each slope gives the expected change in the response for a one-unit increase in that covariate, keeping all other variables in the model constant.
Flipper-length coefficient (\(\widehat{\beta}_1 = 48.89\)):
Bill-length coefficient (\(\widehat{\beta}_2 = 4.96\)):
Intercept (\(\widehat{\beta}_0 = -5836.30\)):
Important: Association is not causality.
Each slope describes an association with the response while the other covariates in the model are held fixed. It does not establish that changing a covariate causes body mass to change.
What is the relationship between \(RSS_{p=2}\) and \(RSS_{p=3}\)?
What is the relationship between \(RSS_{p=2}\) and \(RSS_{p=3}\)?
Solution
Just note that the solution \(\widehat{\pmb{\beta}}\) for the \(p=2\) model is a valid solution for the \(p=3\) model.
Hence, the minimum value of \(RSS\) for the \(p=3\) model must be less than or equal to that for the \(p=2\) model.
In other words, adding covariates to our linear model never increases the minimum value achievable for the residual sum of squares (which is a measure of the “error” made by the model on our data).
Does this mean we should always add as many variables as we can to our model?
Our estimator of \(\sigma^2\), the residual mean square \(\hat{\sigma}^2\), is defined as \[ \hat{\sigma}^2 = \frac{\mathbf{e}^\top\mathbf{e}}{n-(p+1)} = \frac{RSS}{n-(p+1)} \;. \]
Suppose that \(0<R^2<1\) and we add an additional covariate to the model.
Knowing that \(\min RSS_{p=2} \geq \min RSS_{p=3}\), what can we say about \(R^2\) and \(\hat{\sigma}^2\) when we add a new covariate to a model?
Knowing that \(\min RSS_{p=2} \geq \min RSS_{p=3}\), what can we say about \(R^2\) and \(\hat{\sigma}^2\) when we add a new covariate to a model?
Our estimator of \(\sigma^2\), the residual mean square \(\hat{\sigma}^2\), is defined as \[ \hat{\sigma}^2 = \frac{\mathbf{e}^\top\mathbf{e}}{n-(p+1)} = \frac{RSS}{n-(p+1)} \;. \]
Suppose that \(0<R^2<1\) and we add an additional covariate to the model.
Solution
About \(R^2\), recall (Module 06) that \(TSS = \mathbf{y}^\top\mathbf{y}-n\bar{y}^2\) and \[ R^2 = 1 - \frac{RSS}{TSS} \]
\(TSS\) is fixed given the data, and as we saw in Question 3, adding covariates never increases \(RSS\). Hence, \(R^2\) will never decrease with additional covariates.
About \(\hat{\sigma}^2\): \[ \hat{\sigma}^2 = \frac{RSS}{n-(p+1)} \]
With \(\hat\sigma^2\), the numerator \(RSS\) never increases with additional covariates. However, the denominator \(n-(p+1)\) decreases with additional covariates, and so it is possible that \(\hat\sigma^2\) may increase.
To account for the number of predictors in the model, we can use the adjusted \(R^2\), which is \(R^2\) “corrected” for degrees of freedom and defined as \[ \mathrm{adj}\: R^2 = 1 - \frac{\left(\frac{RSS}{n-(p+1)}\right)}{\left(\frac{TSS}{n-1}\right)} = 1 - \frac{(n-1)\hat\sigma^2}{TSS} \;. \]
Unlike \(R^2\), adjusted \(R^2\) could increase, decrease, or stay unchanged with additional covariates. However, it is not lower-bounded by zero.
Both \(R^2\) and adjusted \(R^2\) are provided as output of summary().
MLR Model in Matrix Form: \[\mathbf{Y} = \mathbf{X}\pmb{\beta} + \pmb{\varepsilon}\]
Least Squares Estimate: minimizing \[RSS(\mathbf{b}) = \mathbf{e}^\top\mathbf{e} = (\mathbf{Y}-\mathbf{X}\mathbf{b})^\top(\mathbf{Y}-\mathbf{X}\mathbf{b})\] gives the same normal-equation form as in SLR, \[\mathbf{X}^\top\mathbf{X}\widehat{\pmb{\beta}} = \mathbf{X}^\top\mathbf{Y} \;,\] with unique solution \[\widehat{\pmb{\beta}} = (\mathbf{X}^\top\mathbf{X})^{-1}\mathbf{X}^\top\mathbf{Y}\] whenever \(\mathbf{X}^\top\mathbf{X}\) is invertible.
Invertibility: \(\mathbf{X}^\top\mathbf{X}\) is invertible if and only if \(\mathbf{X}\) has full column rank, \(\operatorname{rank}(\mathbf{X}) = p+1\):
Adding covariates never increases \(RSS\): the parameter space of a \(p\)-covariate model embeds in that of a \((p{+}1)\)-covariate model (by setting the new coefficient to \(0\)), so minimizing over the larger space can only match or beat the smaller one: \[ RSS_{p+1} \le RSS_p \;.\]
Consequences for model-fit statistics, with \(TSS = \mathbf{y}^\top\mathbf{y}-n\bar y^2\) fixed by the data:
© 2025 Rodolfo Lourenzutti – Material Licensed under CC By-SA 4.0