Tutorials › Regression Analysis (Undergraduate) › Weighted Least Squares With Known Variances

Unequal Variance and Robust Uncertainty · Tutorial 539 of 991

Weighted Least Squares With Known Variances

Use known observation variances to fit a regression that gives more influence to more precise observations, and calculate uncertainty under the stated variance model.

Advanced 10 min read

What You'll Learn

  • State the assumptions for weighted least squares with known observation variances
  • Derive the inverse-variance weighting rule from standardized residuals
  • Calculate weighted regression coefficients and their covariance matrix
  • Distinguish known absolute variances from known relative variances
  • Interpret weighted coefficients and confidence intervals in context

Why Weight Observations?

Ordinary least squares gives each observation the same role in minimizing squared residuals. That is appropriate when observations have the same error variance, but not when some measurements are known to be much less precise than others. If the variance pattern is known, weighted least squares (WLS) accounts for it by giving less weight to observations with greater variance.

The weights affect how the fitted line is chosen; they do not change what a regression coefficient means. For example, a slope still describes the change in the model’s mean response associated with a one-unit increase in the predictor, with other predictors held fixed. Its interpretation is an association in the fitted mean model, not by itself a causal effect.

The Model and the Weighting Rule

For \(n\) observations, write the linear regression model as \(\mathbf{y}=\mathbf{X}\boldsymbol{\beta}+\boldsymbol{\varepsilon}\). Here \(\mathbf{y}\) is the response vector, \(\mathbf{X}\) is the design matrix, and \(\boldsymbol{\beta}\) is the vector of regression coefficients. Assume the errors are independent, have mean zero, and have known variances \(\operatorname{Var}(\varepsilon_i)=\sigma_i^2\). Thus the variance may differ across observations. The columns of \(\mathbf{X}\) must be linearly independent so the coefficients can be estimated uniquely. Normal errors are an additional assumption when using the exact normal-based confidence intervals below.

Definition: Weighted least squares minimizes the sum of squared residuals weighted by the inverse of each observation’s error variance. If \(w_i=1/\sigma_i^2\), the WLS estimator is \(\hat{\boldsymbol{\beta}}=(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{y}\), where \(\mathbf{W}\) is the diagonal matrix with entries \(w_i\). The weights are positive; larger variances correspond to smaller weights.

The weighting rule follows from measuring residuals in units of their standard deviations. An observation with variance \(\sigma_i^2\) has standard deviation \(\sigma_i\), so its standardized residual is \(e_i/\sigma_i\), where \(e_i=y_i-\mathbf{x}_i^{\mathsf T}\boldsymbol{\beta}\). Squaring that standardized residual gives \(e_i^2/\sigma_i^2\). WLS therefore minimizes

$$ Q(\boldsymbol{\beta})=\sum_{i=1}^{n}\frac{(y_i-\mathbf{x}_i^{\mathsf T}\boldsymbol{\beta})^2}{\sigma_i^2} =(\mathbf{y}-\mathbf{X}\boldsymbol{\beta})^{\mathsf T}\mathbf{W}(\mathbf{y}-\mathbf{X}\boldsymbol{\beta}). $$

To obtain the estimator, differentiate this quadratic with respect to \(\boldsymbol{\beta}\) and set the derivative equal to zero:

$$ \frac{\partial Q}{\partial\boldsymbol{\beta}} =-2\mathbf{X}^{\mathsf T}\mathbf{W}(\mathbf{y}-\mathbf{X}\boldsymbol{\beta})=\mathbf{0}. $$

Rearranging gives the weighted normal equations, \(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X}\hat{\boldsymbol{\beta}}=\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{y}\). The full-rank assumption makes \(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X}\) invertible, yielding the estimator in the definition. Equivalently, WLS is ordinary least squares applied to the response and design rows after each has been multiplied by \(\sqrt{w_i}=1/\sigma_i\).

Theorem: Under the independent, mean-zero error model with known variances and a full-rank design, the WLS estimator is unbiased and has covariance matrix \((\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\). If the errors are also normal, then \(\hat{\boldsymbol{\beta}}\) has a multivariate normal distribution with mean \(\boldsymbol{\beta}\) and that covariance matrix.

The covariance result can be checked directly. The estimator is a linear transformation of \(\mathbf{y}\), so its covariance is

$$ \begin{aligned} \operatorname{Var}(\hat{\boldsymbol{\beta}}) &=(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1} \mathbf{X}^{\mathsf T}\mathbf{W}\operatorname{Var}(\mathbf{y})\mathbf{W}\mathbf{X} (\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\\ &=(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}, \end{aligned} $$

because \(\operatorname{Var}(\mathbf{y})=\mathbf{W}^{-1}\), and \(\mathbf{W}\mathbf{W}^{-1}\mathbf{W}=\mathbf{W}\). A coefficient’s standard error is the square root of the corresponding diagonal entry of this covariance matrix.

Worked Example: A Weighted Mean

Suppose two independent measurements of the same mean response are 10 and 14 units. Their known error variances are 1 and 4 square units, respectively. Assume the measurements have normal errors and share a common mean \(\beta_0\). This is a regression model with an intercept and no predictors.

The inverse-variance weights are \(w_1=1/1=1\) and \(w_2=1/4=0.25\). The weighted estimate of the mean is

$$ \hat{\beta}_0=\frac{1(10)+0.25(14)}{1+0.25} =\frac{13.5}{1.25}=10.8\text{ units}. $$

Its variance is the reciprocal of the sum of the weights, \(1/1.25=0.8\) square units, so \(SE(\hat{\beta}_0)=\sqrt{0.8}=0.8944\) units. A 95% normal confidence interval is

$$ 10.8\pm1.96(0.8944)=[9.047,\,12.55]\text{ units}. $$

Under the assumed model, the first measurement is more precise: its variance is one-quarter of the second measurement’s variance. The estimate consequently gives it four times the weight. The interval procedure uses the stated known variances; it does not estimate a common residual variance from these two observations.

Weighted Regression With Known Absolute Variances

When the variances are known in their actual units, the covariance matrix of the coefficient estimates is \((\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\), with no additional scale multiplier. Under normal errors, a coefficient estimate divided by its standard error has a standard normal distribution when its hypothesized value is correct. This gives normal-based tests and confidence intervals.

Worked Example: Fitting a Weighted Line

Consider hypothetical responses \(y=(1,3,4)\) at predictor values \(x=(0,1,2)\). Assume the line model \(E(Y_i\mid x_i)=\beta_0+\beta_1x_i\), independent normal errors, and known variances \((1,1/4,1)\) response-units squared. Thus \(\mathbf{W}=\operatorname{diag}(1,4,1)\). With an intercept and slope, the design matrix is full rank because the predictor values are not all equal.

For this design, the weighted cross-product matrix and response cross-product are

$$ \mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X} =\begin{pmatrix}6&6\\6&8\end{pmatrix}, \qquad \mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{y} =\begin{pmatrix}17\\20\end{pmatrix}. $$

For example, the lower-right entry is \(1(0^2)+4(1^2)+1(2^2)=8\). The inverse matrix is

$$ (\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1} =\frac{1}{12}\begin{pmatrix}8&-6\\-6&6\end{pmatrix}. $$

Multiplying by the response cross-product gives

$$ \hat{\boldsymbol{\beta}} =\frac{1}{12}\begin{pmatrix}8&-6\\-6&6\end{pmatrix} \begin{pmatrix}17\\20\end{pmatrix} =\begin{pmatrix}4/3\\1.5\end{pmatrix}. $$

The fitted line is \(\hat{y}=1.333+1.5x\). The estimated slope is 1.5 response units per predictor unit. In context, the model’s mean response increases by 1.5 response units for a one-unit increase in \(x\); this is an association described by the fitted line.

The slope variance is the lower-right entry of the inverse cross-product matrix, \(6/12=0.5\), so its standard error is \(\sqrt{0.5}=0.7071\) response units per predictor unit. A 95% normal confidence interval is

$$ 1.5\pm1.96\sqrt{0.5} =[0.1142,\,2.886]\text{ response units per predictor unit}. $$

Under the assumed normal-error model and known variances, this interval procedure has 95% coverage over repeated samples with the same design. The residuals do not supply an additional variance estimate here: the observation variances were specified as known in absolute units.

Known Relative Variances and an Unknown Scale

Sometimes the variance pattern is known only up to a common positive scale. Write \(\operatorname{Var}(\varepsilon_i)=\sigma^2v_i\), where the positive relative variances \(v_i\) are known but \(\sigma^2\) is unknown. In that case use \(w_i=1/v_i\). The coefficient estimate has the same WLS formula, while its covariance is \(\sigma^2(\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\). Estimate the common scale by \(\hat{\sigma}^2=Q(\hat{\boldsymbol{\beta}})/(n-p)\), where \(p\) is the number of fitted coefficients and \(Q\) is the weighted sum of squared residuals. With normal errors, coefficient-based confidence intervals use a \(t\) distribution with \(n-p\) degrees of freedom. This distinction matters: known relative variances do not mean that the absolute error variances are known.

Worked Example: Estimating Uncertainty With Relative Variances

Use hypothetical responses \(y=(1,2,2,5)\) at \(x=(0,1,2,3)\), with independent normal errors and \(\operatorname{Var}(\varepsilon_i)=\sigma^2v_i\). Suppose the known relative variances are \(v=(1,1/4,1,4)\), but the common scale \(\sigma^2\) is unknown. The corresponding weights are \(w=(1,4,1,0.25)\). The intercept-and-slope design is full rank.

The weighted cross-products are

$$ \mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X} =\begin{pmatrix}25/4&27/4\\27/4&41/4\end{pmatrix}, \qquad \mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{y} =\begin{pmatrix}49/4\\63/4\end{pmatrix}. $$

The determinant of the cross-product matrix is \((25\cdot41-27^2)/16=37/2\), so its inverse is

$$ (\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1} =\frac{1}{37/2}\begin{pmatrix}41/4&-27/4\\-27/4&25/4\end{pmatrix}. $$

Therefore the fitted coefficients are

$$ \hat{\beta}_0=\frac{77}{74}=1.041,\qquad \hat{\beta}_1=\frac{63}{74}=0.8514. $$

The fitted responses at \(x=0,1,2,3\) are \(77/74,140/74,203/74,266/74\). Subtracting these from the observed responses gives residuals \(-3/74,8/74,-55/74,104/74\). Thus the weighted residual sum of squares is

$$ Q(\hat{\boldsymbol{\beta}}) =\left(\frac{-3}{74}\right)^2 +4\left(\frac{8}{74}\right)^2 +\left(\frac{-55}{74}\right)^2 +0.25\left(\frac{104}{74}\right)^2 =\frac{5994}{5476}=1.095. $$

There are \(n-p=4-2=2\) residual degrees of freedom, giving \(\hat{\sigma}^2=1.095/2=0.5475\). The slope’s variance estimate is \(\hat{\sigma}^2\) times the lower-right entry of the inverse cross-product matrix:

$$ \widehat{\operatorname{Var}}(\hat{\beta}_1) =0.5475\left(\frac{25}{74}\right)=0.1850, \qquad SE(\hat{\beta}_1)=\sqrt{0.1850}=0.4301. $$

For a 95% interval, \(t_{0.975,2}\) is approximately 4.303. The resulting interval is \(0.8514\pm4.303(0.4301)=[-1.000,\,2.703]\) response units per predictor unit, to rounding. It is wide because only two residual degrees of freedom remain. Under the stated model, it is an interval for the slope in the mean response, not a range containing 95% of individual responses.

When WLS Helps—and a Common Mistake

WLS can improve precision when the variance pattern is correctly specified: observations with smaller error variance contain more information about the mean and receive greater weight. Its coefficient estimates and standard errors rely on the variance model as well as on the mean model. A wrong mean structure, such as an omitted predictor or curvature, is not repaired merely by changing weights. Likewise, WLS is not a general guarantee against all heteroskedasticity; the weights must represent the observation variances, or their relative pattern, appropriately.

  • Mistake: weighting by the variance. If one observation has variance 4 times as large as another, assigning it 4 times the weight gives the less precise observation more influence. The correction is to use \(w_i=1/\sigma_i^2\), or \(1/v_i\) when variances share an unknown scale.
  • Mistake: treating relative variances as absolute variances. If only \(v_i\) is known in \(\sigma^2v_i\), the common scale still has to be estimated. The coefficient covariance therefore includes \(\sigma^2\), estimated from weighted residuals.
  • Mistake: interpreting the weighted slope as a different kind of effect. Weighting changes the fitted coefficient values and their precision, but the slope’s units and mean-model interpretation remain the change in fitted mean response per predictor unit.
Key takeaway: WLS minimizes squared residuals divided by their variances. With known absolute variances, coefficient covariance is \((\mathbf{X}^{\mathsf T}\mathbf{W}\mathbf{X})^{-1}\); with known relative variances and an unknown common scale, estimate that scale from the weighted residual sum of squares.

Check Your Understanding

Use the stated variance model when answering each question.

  1. If one observation’s error variance is nine times another’s, what is the ratio of their inverse-variance weights?
  2. Why does minimizing standardized squared residuals lead to weights equal to inverse variances rather than inverse standard deviations?
  3. In a weighted line fit with known absolute variances and normal errors, what matrix supplies the variance of the slope estimate?
  4. What additional quantity must be estimated when the variances are known only as \(\sigma^2v_i\)?
  5. A fitted slope is 2.4 response units per predictor unit. State its mean-model interpretation without making a causal claim.