Tutorials › Regression Analysis (Undergraduate) › Deriving the Standard Error of a Fitted Mean

Predictions for Conditional Means · Tutorial 708 of 991

Deriving the Standard Error of a Fitted Mean

Learn how uncertainty in regression coefficients combines to determine the standard error of a fitted conditional mean.

Beginner 9 min read

What You'll Learn

  • Distinguish the standard error of a fitted mean from the variation of individual outcomes.
  • Derive the variance of a fitted mean as a linear combination of coefficient variances and covariances.
  • Express fitted-mean variance using the coefficient covariance matrix and the prediction vector.
  • Calculate a fitted-mean standard error from a supplied covariance matrix.
  • Obtain the usual estimated coefficient covariance matrix under the classical linear regression model.

Why a Fitted Mean Has a Standard Error

A regression equation gives a fitted conditional mean for a specified predictor profile. That fitted value is calculated using estimated coefficients, however, and those coefficients are uncertain. The standard error of the fitted mean summarizes how that coefficient uncertainty affects the estimated mean at the chosen profile. It does not include the additional variation of a new individual outcome around its conditional mean.

The uncertainty depends on the fitted coefficients together, not just on their separate standard errors. When coefficients are correlated, their covariance contributes to the uncertainty of the fitted mean. The derivation below makes that contribution explicit.

Model and Notation

Suppose the regression model has \(p\) coefficients, including an intercept when the model includes one. For observation \(i\), write the model as \(Y_i=\mathbf{x}_i^{T}\boldsymbol{\beta}+\varepsilon_i\). Here \(\mathbf{x}_i\) is the vector of predictor values for that observation, \(\boldsymbol{\beta}\) is the vector of population regression coefficients, and \(\varepsilon_i\) is the error. For a new predictor profile of interest, let \(\mathbf{x}_0\) be its predictor vector, written in the same order and coding as the model columns.

The fitted conditional mean at that profile is \(\hat{\mu}(\mathbf{x}_0)=\mathbf{x}_0^{T}\hat{\boldsymbol{\beta}}\), where \(\hat{\boldsymbol{\beta}}\) is the estimated coefficient vector. For example, an intercept-and-slope model has \(\mathbf{x}_0=(1,x_0)^T\), so the fitted mean is \(\hat{\beta}_0+x_0\hat{\beta}_1\).

Definition: The coefficient covariance matrix is the matrix whose diagonal entries are the variances of the estimated coefficients and whose off-diagonal entries are the covariances between pairs of estimated coefficients. If this matrix is \(V\), then the variance of the fitted mean at profile \(\mathbf{x}_0\) is \(\mathbf{x}_0^T V\mathbf{x}_0\). Replacing the unknown coefficient covariance matrix with an estimate \(\hat{V}\) gives the estimated standard error \(SE\{\hat{\mu}(\mathbf{x}_0)\}=\sqrt{\mathbf{x}_0^T\hat{V}\mathbf{x}_0}\).

Deriving the Variance Formula

The fitted mean is a linear combination of the estimated coefficients. The variance of a linear combination includes both the variance of each coefficient and the covariances between coefficients. For two estimated coefficients, the expansion is:

$$ \operatorname{Var}(a\hat{\beta}_0+b\hat{\beta}_1) =a^2\operatorname{Var}(\hat{\beta}_0) +b^2\operatorname{Var}(\hat{\beta}_1) +2ab\operatorname{Cov}(\hat{\beta}_0,\hat{\beta}_1). $$

The factor of \(2\) appears because the cross-product occurs twice when the matrix product is expanded: once as the covariance of the first coefficient with the second, and once in the reverse order. More generally, let \(V=\operatorname{Cov}(\hat{\boldsymbol{\beta}})\). Expanding the variance of \(\mathbf{x}_0^T\hat{\boldsymbol{\beta}}\) gives the sum of all coefficient variance and covariance terms, which is exactly the quadratic form \(\mathbf{x}_0^T V\mathbf{x}_0\).

$$ \operatorname{Var}\{\hat{\mu}(\mathbf{x}_0)\} =\operatorname{Var}(\mathbf{x}_0^T\hat{\boldsymbol{\beta}}) =\mathbf{x}_0^T\operatorname{Cov}(\hat{\boldsymbol{\beta}})\mathbf{x}_0 =\mathbf{x}_0^T V\mathbf{x}_0. $$

This result follows directly from the variance rule for a linear transformation. For a random vector \(Z\) with covariance matrix \(V\), the variance of \(a^TZ\) is \(a^TVa\). Take \(Z=\hat{\boldsymbol{\beta}}\) and \(a=\mathbf{x}_0\). The result is a variance, in squared response units; its square root is the standard error, in response units.

The Usual Covariance Estimate in Linear Regression

To connect the general result to ordinary least squares, write the observations together as \(\mathbf{Y}=X\boldsymbol{\beta}+\boldsymbol{\varepsilon}\). The columns of \(X\) are the model predictors, including a column of ones if there is an intercept. Assume the conditional mean is correctly represented by this model, \(X\) has full column rank, and, conditional on \(X\), the errors have mean zero and covariance matrix \(\sigma^2 I\). Thus the errors are uncorrelated and have a common variance. Treating \(X\) as fixed, the ordinary least-squares estimator is \(\hat{\boldsymbol{\beta}}=(X^TX)^{-1}X^T\mathbf{Y}\).

Under these assumptions, its covariance matrix follows by applying the covariance rule for a linear transformation. The calculation is:

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

In practice, \(\sigma^2\) is unknown. Under this model, its usual estimate is the residual mean square \(s^2=\mathrm{SSE}/(n-p)\), where \(\mathrm{SSE}\) is the sum of squared residuals and \(n-p\) is the residual degrees of freedom. Therefore the estimated coefficient covariance matrix and fitted-mean standard error are:

$$ \hat{V}=s^2(X^TX)^{-1}, \qquad SE\{\hat{\mu}(\mathbf{x}_0)\} =\sqrt{\mathbf{x}_0^T s^2(X^TX)^{-1}\mathbf{x}_0}. $$

The variance derivation uses the stated mean and covariance assumptions; normal errors are not needed to derive this variance formula. If the model assumptions are not suitable, the usual covariance estimate may not describe coefficient uncertainty correctly. The coefficient covariance matrix should be taken from an analysis whose assumptions match the situation.

Worked Example: A Fitted Mean From Two Correlated Coefficients

Suppose a hypothetical regression predicts a response in minutes from a predictor measured in hours. At a profile of \(x_0=3\) hours, the estimated intercept is \(12\) minutes and the estimated slope is \(2.4\) minutes per hour. Suppose the estimated coefficient covariance matrix, in the order intercept then slope, is:

$$ \hat{V} = \begin{pmatrix} 4 & -0.30\\ -0.30 & 0.04 \end{pmatrix}, \qquad \mathbf{x}_0= \begin{pmatrix} 1\\3 \end{pmatrix}. $$

The fitted mean is \(12+(2.4)(3)=19.2\) minutes. For its estimated variance, include the intercept variance, the slope variance, and their covariance:

$$ \begin{aligned} \widehat{\operatorname{Var}}\{\hat{\mu}(3)\} &=1^2(4)+3^2(0.04)+2(1)(3)(-0.30)\\ &=4+0.36-1.80\\ &=2.56\ \text{minutes}^2. \end{aligned} $$

Consequently, the estimated standard error is \(\sqrt{2.56}=1.60\) minutes. The negative covariance reduces the variance of this particular linear combination; omitting it would give \(4.36\) minutes squared instead. That omission would not calculate the standard error for the stated fitted mean.

Using the Matrix Formula in Multiple Regression

The same calculation applies when a fitted mean uses several predictors. The vector \(\mathbf{x}_0\) must include every model column, with the correct coding. Each diagonal entry of \(\hat{V}\) contributes a coefficient variance, while every off-diagonal covariance contributes a cross-term. In general, a covariance can either increase or decrease the total variance, depending on its sign and on the entries of \(\mathbf{x}_0\).

Worked Example: Combining Three Coefficient Estimates

Consider a hypothetical multiple regression with an intercept, a quantitative predictor \(x_1\), and a two-level indicator \(x_2\) coded \(0\) or \(1\). Suppose the response is measured in dollars. At the profile \(x_1=2,\ x_2=1\), the design vector is \(\mathbf{x}_0=(1,2,1)^T\). Assume the estimated coefficient vector is \((50,3,-2)^T\), and the estimated coefficient covariance matrix is:

$$ \hat{V} = \begin{pmatrix} 9 & 1 & -0.5\\ 1 & 4 & 0.4\\ -0.5 & 0.4 & 1 \end{pmatrix}. $$

The fitted mean is \(50+(3)(2)+(-2)(1)=54\) dollars. Its estimated variance is the sum of the three diagonal contributions and the three covariance contributions, each counted twice:

$$ \begin{aligned} \mathbf{x}_0^T\hat{V}\mathbf{x}_0 &=1^2(9)+2^2(4)+1^2(1)\\ &\quad+2(1)(2)(1)+2(1)(1)(-0.5)+2(2)(1)(0.4)\\ &=9+16+1+4-1+1.6\\ &=30.6\ \text{dollars}^2. \end{aligned} $$

The standard error is \(\sqrt{30.6}=5.532\) dollars. The numerical value is calculated for this particular profile: the coefficient estimates and the covariance matrix alone do not give one standard error that applies to every possible profile.

Calculating From the Simple-Regression Covariance Estimate

In simple regression, the general matrix formula can be evaluated using familiar summaries. If \(x\) is the predictor, let \(\bar{x}\) be its sample mean and \(S_{xx}=\sum_{i=1}^n(x_i-\bar{x})^2\). With an intercept, the estimated coefficient covariance matrix is:

$$ \hat{V} =s^2 \begin{pmatrix} \frac{1}{n}+\frac{\bar{x}^2}{S_{xx}} & -\frac{\bar{x}}{S_{xx}}\\ -\frac{\bar{x}}{S_{xx}} & \frac{1}{S_{xx}} \end{pmatrix}. $$

Multiplying on both sides by \((1,x_0)^T\) and its transpose gives an equivalent expression:

$$ \widehat{\operatorname{Var}}\{\hat{\mu}(x_0)\} =s^2\left\{\frac{1}{n}+\frac{(x_0-\bar{x})^2}{S_{xx}}\right\}. $$

This identity is an algebraic rearrangement of the matrix formula: the terms involving \(\bar{x}\) combine with the \(x_0^2/S_{xx}\) term to form \((x_0-\bar{x})^2/S_{xx}\). The expression remains an estimated variance, so its square root is the estimated standard error.

Worked Example: Computing the Standard Error From Regression Summaries

For a hypothetical simple regression, suppose \(n=10\), \(\bar{x}=5\) degrees Celsius, \(S_{xx}=20\) degrees Celsius squared, and the residual standard deviation is \(s=3\) kilowatt-hours. The fitted regression equation is \(\hat{y}=4+1.2x\), and the target profile is \(x_0=7\) degrees Celsius. Assume the linear conditional-mean model is appropriate, errors have mean zero and a common variance, and observations are uncorrelated. The predictor varies because \(S_{xx}>0\), so the two regression coefficients are estimable.

First calculate the fitted mean: \(4+(1.2)(7)=12.4\) kilowatt-hours. The estimated variance of this fitted mean is:

$$ \begin{aligned} \widehat{\operatorname{Var}}\{\hat{\mu}(7)\} &=3^2\left\{\frac{1}{10}+\frac{(7-5)^2}{20}\right\}\\ &=9(0.10+0.20)\\ &=2.70\ \text{kilowatt-hours}^2. \end{aligned} $$

Thus, the standard error is \(\sqrt{2.70}=1.643\) kilowatt-hours. The same answer follows from the coefficient covariance matrix. Here,

$$ \hat{V} =9 \begin{pmatrix} 0.10+\frac{25}{20} & -\frac{5}{20}\\ -\frac{5}{20} & \frac{1}{20} \end{pmatrix} = \begin{pmatrix} 12.15 & -2.25\\ -2.25 & 0.45 \end{pmatrix}. $$

Using \(\mathbf{x}_0=(1,7)^T\), the variance is \(12.15+7^2(0.45)+2(1)(7)(-2.25)=12.15+22.05-31.50=2.70\) kilowatt-hours squared, matching the calculation above.

Common Mistake: Dropping the Covariance Terms

A tempting but generally incorrect calculation is to combine coefficient standard errors as if the estimates were independent. For a two-coefficient fitted mean, this amounts to using only \(a^2\operatorname{Var}(\hat{\beta}_0)+b^2\operatorname{Var}(\hat{\beta}_1)\). The correct formula also contains \(2ab\operatorname{Cov}(\hat{\beta}_0,\hat{\beta}_1)\). Coefficient estimates from a regression are often correlated, so the covariance is not automatically zero.

Another error is to report the variance itself as the standard error. The matrix product \(\mathbf{x}_0^T\hat{V}\mathbf{x}_0\) has squared response units; take its nonnegative square root to obtain an \(SE\) in response units. Finally, this is uncertainty in an estimated conditional mean. It is not the standard deviation of individual outcomes at the profile, which also includes their outcome-to-outcome variation around that mean.

Key takeaway: For a fitted mean \(\hat{\mu}(\mathbf{x}_0)=\mathbf{x}_0^T\hat{\boldsymbol{\beta}}\), calculate its estimated variance as \(\mathbf{x}_0^T\hat{V}\mathbf{x}_0\), retaining all coefficient covariance terms. The standard error is the square root of that variance.

Check Your Understanding

Use the definitions and formulas above to answer these questions.

  1. In a model with an intercept and one slope, write the fitted-mean variance at \(x_0\) using the two coefficient variances and their covariance.
  2. Why does the covariance term appear twice in the expanded variance formula?
  3. If \(\mathbf{x}_0^T\hat{V}\mathbf{x}_0=16\) response-units squared, what is the fitted-mean standard error, including its units?
  4. What assumptions give the usual coefficient covariance estimate \(s^2(X^TX)^{-1}\)?
  5. Explain why omitting coefficient covariance terms can give an incorrect standard error, even when both coefficient standard errors are known.