Tutorials › Statistical Decision Theory › Least Squares Risk Under Gaussian Errors

Quadratic-Risk Estimation Problems · Tutorial 401 of 982

Least Squares Risk Under Gaussian Errors

Learn how the design matrix determines ordinary least squares risk for coefficient estimation and prediction of the regression mean.

Intermediate 10 min read

What You'll Learn

  • State the assumptions for the full-rank Gaussian linear model.
  • Derive the bias and covariance matrix of the ordinary least-squares estimator.
  • Calculate expected squared coefficient loss from the covariance matrix.
  • Derive expected squared in-sample prediction loss using the projection matrix.
  • Distinguish prediction of a regression mean from prediction of a noisy future response.
  • Work out coefficient and prediction risks for explicit designs.

Why the Design Matters for Risk

In a linear model, ordinary least squares (OLS) estimates a vector of regression coefficients from a response vector. Its errors are not summarized by a single variance: uncertainty in each coefficient, and the resulting uncertainty in fitted means, depend on the design matrix. A risk calculation makes that dependence explicit and distinguishes two targets that are easy to confuse: the regression mean and a future noisy response.

Throughout, treat the design matrix as fixed. Let there be \(n\) observations and \(p\) coefficients, with \(n \ge p\). Assume the columns of the design matrix are linearly independent. The model is

$$ \mathbf Y=\mathbf X\boldsymbol\beta+\boldsymbol\varepsilon,\qquad \boldsymbol\varepsilon\sim N_n(\mathbf 0,\sigma^2\mathbf I_n),\quad \sigma^2>0. $$

Here \(\mathbf Y\) is the \(n\)-vector of responses, \(\mathbf X\) is the fixed \(n\times p\) design matrix, and \(\boldsymbol\beta\) is the unknown coefficient vector. The error assumption says that the errors have mean zero, common variance \(\sigma^2\), and zero covariance between distinct observations; their joint distribution is multivariate normal. Full column rank ensures that \(\mathbf X^\mathsf T\mathbf X\) is invertible.

Definition: Under squared coefficient loss, the loss from reporting a vector \(\mathbf a\) when the true coefficient vector is \(\boldsymbol\beta\) is \(\|\mathbf a-\boldsymbol\beta\|^2\). The coefficient risk of an estimator \(\hat{\boldsymbol\beta}\) is \(E[\|\hat{\boldsymbol\beta}-\boldsymbol\beta\|^2]\). The in-sample squared prediction loss for the regression mean is \(\|\mathbf X\hat{\boldsymbol\beta}-\mathbf X\boldsymbol\beta\|^2\), with risk given by its expectation.

OLS Bias and Covariance

The least-squares estimator minimizes \(\|\mathbf Y-\mathbf X\mathbf a\|^2\) over coefficient vectors \(\mathbf a\). Under full column rank, its unique solution is

$$ \hat{\boldsymbol\beta} =(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf X^\mathsf T\mathbf Y. $$

The following result gives its distributional properties. These properties are conditional on the fixed design; no averaging over a random design is involved.

Theorem: In the stated full-rank Gaussian linear model, \(\hat{\boldsymbol\beta}\) is unbiased, has covariance matrix \(\sigma^2(\mathbf X^\mathsf T\mathbf X)^{-1}\), and is normally distributed as \(N_p(\boldsymbol\beta,\sigma^2(\mathbf X^\mathsf T\mathbf X)^{-1})\).

Proof. Put \(\mathbf A=(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf X^\mathsf T\). Since \(\mathbf A\mathbf X=\mathbf I_p\), substituting the model into the OLS formula gives

$$ \hat{\boldsymbol\beta} =\mathbf A(\mathbf X\boldsymbol\beta+\boldsymbol\varepsilon) =\boldsymbol\beta+\mathbf A\boldsymbol\varepsilon. $$

Taking expectations and using \(E[\boldsymbol\varepsilon]=\mathbf 0\) yields \(E[\hat{\boldsymbol\beta}]=\boldsymbol\beta\), so the bias is zero. Applying the covariance rule for a fixed linear transformation gives

$$ \begin{aligned} \operatorname{Cov}(\hat{\boldsymbol\beta}) &=\mathbf A\operatorname{Cov}(\boldsymbol\varepsilon)\mathbf A^\mathsf T\\ &=\sigma^2(\mathbf X^\mathsf T\mathbf X)^{-1} \mathbf X^\mathsf T\mathbf X (\mathbf X^\mathsf T\mathbf X)^{-1}\\ &=\sigma^2(\mathbf X^\mathsf T\mathbf X)^{-1}. \end{aligned} $$

Finally, \(\hat{\boldsymbol\beta}\) is a fixed linear transformation of a multivariate normal vector, plus the fixed vector \(\boldsymbol\beta\). Its mean and covariance, just calculated, therefore give the stated normal distribution. \(\square\)

Expected Coefficient and In-Sample Prediction Loss

Write \(\mathbf e=\hat{\boldsymbol\beta}-\boldsymbol\beta\). Because the estimator is unbiased, \(E[\mathbf e]=\mathbf 0\). For any zero-mean random vector with finite second moments, the expected squared Euclidean norm is the trace of its covariance matrix: \(\|\mathbf e\|^2=\operatorname{tr}(\mathbf e\mathbf e^\mathsf T)\), so taking expectations gives \(E[\|\mathbf e\|^2]=\operatorname{tr}(\operatorname{Cov}(\mathbf e))\). Applying this identity to the covariance above gives the coefficient risk.

Result: The expected squared coefficient loss of OLS is \[ E[\|\hat{\boldsymbol\beta}-\boldsymbol\beta\|^2] =\sigma^2\operatorname{tr}\{(\mathbf X^\mathsf T\mathbf X)^{-1}\}. \]

The in-sample error in fitted regression means is \(\mathbf X\mathbf e\), so its squared norm is \(\mathbf e^\mathsf T\mathbf X^\mathsf T\mathbf X\mathbf e\). Taking expectations and using the trace identity for a quadratic form gives

$$ \begin{aligned} E[\|\mathbf X\mathbf e\|^2] &=\operatorname{tr}\{\mathbf X^\mathsf T\mathbf X E[\mathbf e\mathbf e^\mathsf T]\}\\ &=\sigma^2\operatorname{tr}\{ \mathbf X^\mathsf T\mathbf X(\mathbf X^\mathsf T\mathbf X)^{-1}\}\\ &=p\sigma^2. \end{aligned} $$

Equivalently, the matrix \(\mathbf P_X=\mathbf X(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf X^\mathsf T\) is the projection matrix onto the column space of \(\mathbf X\), and its trace is \(p\). Thus the expected total squared error in fitted means is \(p\sigma^2\), and the average across the \(n\) design points is \(p\sigma^2/n\). This total risk does not depend on the particular full-rank design, although the coefficient risk generally does.

Result: For a specified covariate vector \(\mathbf x_0\), the variance of the estimated regression mean \(\mathbf x_0^\mathsf T\hat{\boldsymbol\beta}\) is \(\sigma^2\mathbf x_0^\mathsf T(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf x_0\). If the target is instead a new response \(Y_0=\mathbf x_0^\mathsf T\boldsymbol\beta+\varepsilon_0\), with an independent error \(\varepsilon_0\sim N(0,\sigma^2)\), the expected squared prediction error is this variance plus \(\sigma^2\).

To see the distinction, the error in estimating the regression mean at \(\mathbf x_0\) is \(\mathbf x_0^\mathsf T(\hat{\boldsymbol\beta}-\boldsymbol\beta)\). Its mean is zero, and its variance is the displayed quadratic form. For a future response, the prediction error is \(\mathbf x_0^\mathsf T(\hat{\boldsymbol\beta}-\boldsymbol\beta)-\varepsilon_0\). Independence makes the covariance term zero, and the two variances add. The extra \(\sigma^2\) is irreducible response noise, not uncertainty in the fitted mean.

Worked Risk Calculations

Worked Example: OLS Risks in a Simple Regression

Let \(\mathbf X=\begin{pmatrix}1&0\\1&1\\1&2\end{pmatrix}\), \(\boldsymbol\beta=(1,1)^\mathsf T\), and \(\sigma^2=1\). The mean response vector is \(\mathbf X\boldsymbol\beta=(1,2,3)^\mathsf T\), so \(\mathbf Y=(1,2,3)^\mathsf T+\boldsymbol\varepsilon\). Calculate the covariance and both total risks.

First, \[ \mathbf X^\mathsf T\mathbf X =\begin{pmatrix}3&3\\3&5\end{pmatrix}, \qquad (\mathbf X^\mathsf T\mathbf X)^{-1} =\frac{1}{6}\begin{pmatrix}5&-3\\-3&3\end{pmatrix}. \] The inverse follows because the determinant is \(3(5)-3(3)=6\). Therefore the estimator is unbiased and its covariance is \(\frac{1}{6}\begin{pmatrix}5&-3\\-3&3\end{pmatrix}\).

The coefficient risk is the trace: \[ E[\|\hat{\boldsymbol\beta}-\boldsymbol\beta\|^2] =\frac{5+3}{6}=\frac{4}{3}. \] There are \(p=2\) coefficients, so the expected total in-sample squared prediction error for the regression means is \(p\sigma^2=2\). Its average per design point is \(2/3\).

For a check using actual data, take \(\mathbf y=(1,2,4)^\mathsf T\). Then \(\mathbf X^\mathsf T\mathbf y=(7,10)^\mathsf T\), and \[ \hat{\boldsymbol\beta} =\frac{1}{6}\begin{pmatrix}5&-3\\-3&3\end{pmatrix} \begin{pmatrix}7\\10\end{pmatrix} =\begin{pmatrix}5/6\\3/2\end{pmatrix}. \] This particular estimate differs from the true vector, as expected in a noisy sample; the risks above average over the error distribution and do not depend on this one observed response.

Worked Example: Orthogonal Columns and a New Prediction

Suppose the design has an intercept and predictor values \(-3,-1,1,3\), so \(\mathbf X^\mathsf T\mathbf X=\begin{pmatrix}4&0\\0&20\end{pmatrix}\). Let \(\sigma^2=4\). Calculate the coefficient risk, in-sample prediction risk, and uncertainty for estimating the mean at \(\mathbf x_0=(1,2)^\mathsf T\).

The covariance matrix is \[ 4(\mathbf X^\mathsf T\mathbf X)^{-1} =4\begin{pmatrix}1/4&0\\0&1/20\end{pmatrix} =\begin{pmatrix}1&0\\0&1/5\end{pmatrix}. \] Its trace is \(6/5\), so the expected squared coefficient loss is \(6/5\). The expected total in-sample squared prediction loss is \(p\sigma^2=2(4)=8\).

At the new covariate vector, \[ \operatorname{Var}(\mathbf x_0^\mathsf T\hat{\boldsymbol\beta}) =4\left(\frac{1^2}{4}+\frac{2^2}{20}\right) =4\left(\frac{1}{4}+\frac{1}{5}\right) =\frac{9}{5}. \] Thus the expected squared error for estimating the regression mean is \(9/5\). Predicting an independent future response at the same covariate adds its error variance \(4\), giving \(9/5+4=29/5\).

Worked Example: Risk Under a Second Full-Rank Design

Let the predictor values be \(0,2,4,6\), with an intercept, and take \(\sigma^2=4\). Then \[ \mathbf X^\mathsf T\mathbf X =\begin{pmatrix}4&12\\12&56\end{pmatrix}, \qquad \det(\mathbf X^\mathsf T\mathbf X)=4(56)-12^2=80. \] Compute the total coefficient and prediction risks, and the mean-prediction variance at \(\mathbf x_0=(1,3)^\mathsf T\).

The inverse and covariance are \[ (\mathbf X^\mathsf T\mathbf X)^{-1} =\frac{1}{80}\begin{pmatrix}56&-12\\-12&4\end{pmatrix}, \qquad \operatorname{Cov}(\hat{\boldsymbol\beta}) =\frac{1}{20}\begin{pmatrix}56&-12\\-12&4\end{pmatrix}. \] The trace of the covariance is \((56+4)/20=3\), so the coefficient risk is \(3\). The in-sample squared prediction risk remains \(2\sigma^2=8\).

For the regression mean at \(\mathbf x_0\), the variance is \[ 4\mathbf x_0^\mathsf T(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf x_0 =\frac{4}{80}(56-72+36) =1. \] A future response at that point has expected squared prediction error \(1+4=5\). This example shows why the same coefficient risk and in-sample total risk formulas should not be mistaken for the uncertainty at every individual covariate value.

Interpretation and a Common Pitfall

The coefficient-risk formula depends on \((\mathbf X^\mathsf T\mathbf X)^{-1}\): a design that provides less information in some coefficient direction can make squared coefficient error larger. The in-sample total prediction risk has a simpler form, \(p\sigma^2\), because the fitted values vary only in the \(p\)-dimensional column space of the design. At a particular new covariate vector, however, uncertainty depends on its position relative to the design, through \(\mathbf x_0^\mathsf T(\mathbf X^\mathsf T\mathbf X)^{-1}\mathbf x_0\).

Common mistake: treating residual error as prediction error for the regression mean. The residual vector is \(\mathbf Y-\mathbf X\hat{\boldsymbol\beta}\); it compares observed responses, which contain noise, with fitted means. It is not the vector \(\mathbf X\hat{\boldsymbol\beta}-\mathbf X\boldsymbol\beta\), because the true mean vector is not observed directly. Nor should the expected in-sample squared error \(p\sigma^2\) be used as the risk for predicting a new response at any chosen covariate. For a new response, add the independent noise variance; for a particular mean prediction, use the corresponding quadratic form.

Check Your Understanding

Use the full-rank Gaussian linear model and squared losses defined above.

  1. Why does full column rank of \(\mathbf X\) ensure that the OLS estimator is uniquely defined?
  2. For \(\sigma^2=2\) and \(p=3\), what is the expected total in-sample squared prediction loss for the regression means?
  3. What matrix determines the expected squared coefficient loss, and why does its trace appear?
  4. At a fixed covariate vector, explain the difference between the mean-prediction variance and the expected squared error for a future response.
  5. For the design with \(\mathbf X^\mathsf T\mathbf X=\operatorname{diag}(5,10)\) and \(\sigma^2=1\), calculate the coefficient risk.
Clinical Biostats