A Note on Weighted Least Squares
Vector 4:3, page 115
Transcribed from the printed issue; not yet reviewed. Read it in the PDF of the issue, page 115
It is well known that the APL domino function includes a routine to obtain least squares fits of a straight line to a set of observations. Specifically, suppose that the model to be fitted to a set of multivariate data containing \(n\) observations is
where the residuals \(e_i\) (\(i = 1,2,\ldots n\)) are assumed to be identically and independently distributed with an error variance which has to be estimated along with the b’s. Suppose further that the data is presented in the form of a matrix with \(n\) rows and \((p+2)\) columns, the leftmost of which gives the y values, and the remainder the x-values, starting with a column of 1’s to correspond to the fitting of the constant term \(b_0\). The vector of regression coefficients is then given by :
and the residuals by
The error variance is given by
and the variances of the b’s by
where IMS stands for “Inverse Matrix Squared”, a function which as \((X'X)^{-1}\) occurs repeatedly in analysing residuals. It is defined as
In practice there are situations in which the assumptions that the residuals are identically distributed is not tenable, e.g. if the population is in fact several subpopulations whose residual variances are proportional to one of the x values, or if the residual variances corresponding to particular x values are known as the result of repeated experimentation, as might happen say in a physics experiment. The appropriate analysis is then weighted least squares. Assume that the variance corresponding to the ith. observation is \(w_i\) times the error variance, where \((w_1, w_2,\ldots\, w_n)\) are the items of a known vector \(W\). The appropriate regression coefficients, error variance, and variances of the b’s are the BS, EVAR, and BVAR of the data matrix
where DIAG is a function which constructs a diagonal matrix with the weights \(w_1 \ldots w_n\) as the leading diagonal, e.g.
To give a specific example, consider the data
| x : | 3 | 5 | 8 | 12 | 15 | 17 | 20 |
|---|---|---|---|---|---|---|---|
| y : | 0.8 | 1.2 | 2.5 | 4.9 | 8.3 | 12.3 | 17.6 |
as a candidate for a least squares fit
so that R is
The coefficients \(b_0\) and \(b_1\) are given by
If, however, there is evidence that the spread of the residuals increases with \(x\) so that a plot of \(e\) vs \(x\) has the appearance

then weighted least squares is appropriate. Assuming weights proportional to \(x\) gives a regression line \(y = -2.562 + 0.8192x\). As the graph below shows the effect is to downgrade the importance of the last two points which are in the relatively more variable x region.

The more the weights are “strengthened”, e.g. by taking them to be the squares of the x values which gives \(y = -1.721 + 0.709\,x\), the more closely does the weighted squares line track the smaller value points.
If the model
is chosen, i.e. the data matrix is changed to
the fitted quadratics are
and
The effect of weighted least squares is to cause the regression parabola to approach closer to the lowest x-value point as the graph below illustrates.
