Weighted least squares

Method for model fitting in statistics

This article or section may need to be cleaned up or summarized because it has been split from/to Least squares and Linear least squares (mathematics).

|

Part of a series on

Regression analysis
Models

* Linear regression
* Simple regression
* Polynomial regression
* General linear model

* Generalized linear model
* Vector generalized linear model
* Discrete choice
* Binomial regression
* Binary regression
* Logistic regression
* Multinomial logistic regression
* Mixed logit
* Probit
* Multinomial probit
* Ordered logit
* Ordered probit
* Poisson

* Multilevel model
* Fixed effects
* Random effects
* Linear mixed-effects model
* Nonlinear mixed-effects model

* Nonlinear regression
* Nonparametric
* Semiparametric
* Robust
* Quantile
* Isotonic
* Principal components
* Least angle
* Local
* Segmented

* Errors-in-variables

Estimation

* Least squares
* Linear
* Non-linear

* Ordinary
* Weighted
* Generalized
* Generalized estimating equation

* Partial
* Total
* Non-negative
* Ridge regression
* Regularized

* Least absolute deviations
* Iteratively reweighted
* Bayesian
* Bayesian multivariate
* Least-squares spectral analysis

Background

* Regression validation
* Mean and predicted response
* Errors and residuals
* Goodness of fit
* Studentized residual
* Gauss–Markov theorem

* Mathematics portal

* v
* t
* e

Weighted least squares (WLS), also known as weighted linear regression,[1][2] is a generalization of ordinary least squares and linear regression in which knowledge of the unequal variance of observations (heteroscedasticity) is incorporated into the regression. WLS is also a specialization of generalized least squares, when all the off-diagonal entries of the covariance matrix of the errors, are null.

## Formulation

[edit]

The fit of a model to a data point is measured by its residual,  r i {\displaystyle r_{i}} , defined as the difference between a measured value of the dependent variable,  y i {\displaystyle y_{i}} and the value predicted by the model,  f ( x i , β ) {\displaystyle f(x_{i},{\boldsymbol {\beta }})} :  r i ( β ) = y i − f ( x i , β ) . {\displaystyle r_{i}({\boldsymbol {\beta }})=y_{i}-f(x_{i},{\boldsymbol {\beta }}).}

If the errors are uncorrelated and have equal variance, then the function  S ( β ) = ∑ i r i ( β ) 2 , {\displaystyle S({\boldsymbol {\beta }})=\sum _{i}r_{i}({\boldsymbol {\beta }})^{2},} is minimised at  β ^ {\displaystyle {\boldsymbol {\hat {\beta }}}} , such that  ∂ S ∂ β j ( β ^ ) = 0 {\displaystyle {\frac {\partial S}{\partial \beta _{j}}}({\hat {\boldsymbol {\beta }}})=0} .

The Gauss–Markov theorem shows that, when this is so,  β ^ {\displaystyle {\hat {\boldsymbol {\beta }}}} is a best linear unbiased estimator (BLUE). If, however, the measurements are uncorrelated but have different uncertainties, a modified approach might be adopted. Aitken showed that when a weighted sum of squared residuals is minimized,  β ^ {\displaystyle {\hat {\boldsymbol {\beta }}}} is the BLUE if each weight is equal to the reciprocal of the variance of the measurement  S = ∑ i = 1 n W i i r i 2 , W i i = 1 σ i 2 {\displaystyle {\begin{aligned}S&=\sum _{i=1}^{n}W_{ii}{r_{i}}^{2},&W_{ii}&={\frac {1}{{\sigma _{i}}^{2}}}\end{aligned}}}

The gradient equations for this sum of squares are  − 2 ∑ i W i i ∂ f ( x i , β ) ∂ β j r i = 0 , j = 1 , … , m {\displaystyle -2\sum _{i}W_{ii}{\frac {\partial f(x_{i},{\boldsymbol {\beta }})}{\partial \beta _{j}}}r_{i}=0,\quad j=1,\ldots ,m}

which, in a linear least squares system give the modified normal equations,  ∑ i = 1 n ∑ k = 1 m X i j W i i X i k β ^ k = ∑ i = 1 n X i j W i i y i , j = 1 , … , m . {\displaystyle \sum _{i=1}^{n}\sum _{k=1}^{m}X_{ij}W_{ii}X_{ik}{\hat {\beta }}_{k}=\sum _{i=1}^{n}X_{ij}W_{ii}y_{i},\quad j=1,\ldots ,m\,.} The matrix  X {\displaystyle X} above is as defined in the corresponding discussion of linear least squares.

When the observational errors are uncorrelated and the weight matrix, W=Ω−1, is diagonal, these may be written as  ( X T W X ) β ^ = X T W y . {\displaystyle \mathbf {\left(X^{\textsf {T}}WX\right){\hat {\boldsymbol {\beta }}}=X^{\textsf {T}}Wy} .}

If the errors are correlated, the resulting estimator is the BLUE if the weight matrix is equal to the inverse of the variance-covariance matrix of the observations.

When the errors are uncorrelated, it is convenient to simplify the calculations to factor the weight matrix as  w i i = W i i {\displaystyle w_{ii}={\sqrt {W_{ii}}}} . The normal equations can then be written in the same form as ordinary least squares:  ( X ′ T X ′ ) β ^ = X ′ T y ′ {\displaystyle \mathbf {\left(X'^{\textsf {T}}X'\right){\hat {\boldsymbol {\beta }}}=X'^{\textsf {T}}y'} \,}

where we define the following scaled matrix and vector:  X ′ = diag ⁡ ( w ) X , y ′ = diag ⁡ ( w ) y = y ⊘ σ . {\displaystyle {\begin{aligned}\mathbf {X'} &=\operatorname {diag} \left(\mathbf {w} \right)\mathbf {X} ,\\\\\mathbf {y'} &=\operatorname {diag} \left(\mathbf {w} \right)\mathbf {y} =\mathbf {y} \oslash \mathbf {\sigma } .\end{aligned}}}

This is a type of whitening transformation; the last expression involves an entrywise division.

For non-linear least squares systems a similar argument shows that the normal equations should be modified as follows.  ( J T W J ) Δ β = J T W Δ y . {\displaystyle \mathbf {\left(J^{\textsf {T}}WJ\right)\,{\boldsymbol {\Delta }}\beta =J^{\textsf {T}}W\,{\boldsymbol {\Delta }}y} .\,}

Note that for empirical tests, the appropriate W is not known for sure and must be estimated. For this feasible generalized least squares (FGLS) techniques may be used; in this case it is specialized for a diagonal covariance matrix, thus yielding a feasible weighted least squares solution.

If the uncertainty of the observations is not known from external sources, then the weights could be estimated from the given observations. This can be useful, for example, to identify outliers. After the outliers have been removed from the data set, the weights should be reset to one.[3]

## Motivation

[edit]

In some cases the observations may be weighted—for example, they may not be equally reliable. In this case, one can minimize the weighted sum of squares:  a r g m i n β ∑ i = 1 n w i | y i − ∑ j = 1 m X i j β j | 2 = a r g m i n β ‖ W 1 2 ( y − X β ) ‖ 2 . {\displaystyle {\underset {\boldsymbol {\beta }}{\operatorname {arg\ min} }}\,\sum _{i=1}^{n}w_{i}\left|y_{i}-\sum _{j=1}^{m}X_{ij}\beta _{j}\right|^{2}={\underset {\boldsymbol {\beta }}{\operatorname {arg\ min} }}\,\left\|W^{\frac {1}{2}}\left(\mathbf {y} -X{\boldsymbol {\beta }}\right)\right\|^{2}.} where wi > 0 is the weight of the ith observation, and W is the diagonal matrix of such weights.

The weights should, ideally, be equal to the reciprocal of the variance of the measurement. (This implies that the observations are uncorrelated. If the observations are correlated, the expression  S = ∑ k ∑ j r k W k j r j {\textstyle S=\sum _{k}\sum _{j}r_{k}W_{kj}r_{j}\,} applies. In this case the weight matrix should ideally be equal to the inverse of the variance-covariance matrix of the observations).[3] The normal equations are then:  ( X T W X ) β ^ = X T W y . {\displaystyle \left(X^{\textsf {T}}WX\right){\hat {\boldsymbol {\beta }}}=X^{\textsf {T}}W\mathbf {y} .}

This method is used in iteratively reweighted least squares.

## Solution

[edit]

### Parameter errors and correlation

[edit]

The estimated parameter values are linear combinations of the observed values  β ^ = ( X T W X ) − 1 X T W y . {\displaystyle {\hat {\boldsymbol {\beta }}}=(X^{\textsf {T}}WX)^{-1}X^{\textsf {T}}W\mathbf {y} .}

Therefore, an expression for the estimated variance-covariance matrix of the parameter estimates can be obtained by error propagation from the errors in the observations. Let the variance-covariance matrix for the observations be denoted by M and that of the estimated parameters by Mβ. Then  M β = ( X T W X ) − 1 X T W M W T X ( X T W T X ) − 1 . {\displaystyle M^{\beta }=\left(X^{\textsf {T}}WX\right)^{-1}X^{\textsf {T}}WMW^{\textsf {T}}X\left(X^{\textsf {T}}W^{\textsf {T}}X\right)^{-1}.}

When W = M−1, this simplifies to  M β = ( X T W X ) − 1 . {\displaystyle M^{\beta }=\left(X^{\textsf {T}}WX\right)^{-1}.}

When unit weights are used (W = I, the identity matrix), it is implied that the experimental errors are uncorrelated and all equal: M = σ2I, where σ2 is the a priori variance of an observation. In any case, σ2 is approximated by the reduced chi-squared χ ν 2 {\displaystyle \chi _{\nu }^{2}} :  M β = χ ν 2 ( X T W X ) − 1 , χ ν 2 = S / ν , {\displaystyle {\begin{aligned}M^{\beta }&=\chi _{\nu }^{2}\left(X^{\textsf {T}}WX\right)^{-1},\\\\\chi _{\nu }^{2}&=S/\nu ,\end{aligned}}}

where S is the minimum value of the weighted objective function:  S = r T W r = ‖ W 1 2 ( y − X β ^ ) ‖ 2 . {\displaystyle S=r^{\textsf {T}}Wr=\left\|W^{\frac {1}{2}}\left(\mathbf {y} -X{\hat {\boldsymbol {\beta }}}\right)\right\|^{2}.}

The denominator,  ν = n − m {\displaystyle \nu =n-m} , is the number of degrees of freedom; see effective degrees of freedom for generalizations for the case of correlated observations.

In all cases, the variance of the parameter estimate  β ^ i {\displaystyle {\hat {\beta }}_{i}} is given by  M i i β {\displaystyle M_{ii}^{\beta }} and the covariance between the parameter estimates  β ^ i {\displaystyle {\hat {\beta }}_{i}} and  β ^ j {\displaystyle {\hat {\beta }}_{j}} is given by  M i j β {\displaystyle M_{ij}^{\beta }} . The standard deviation is the square root of variance,  σ i = M i i β {\displaystyle \sigma _{i}={\sqrt {M_{ii}^{\beta }}}} , and the correlation coefficient is given by  ρ i j = M i j β / ( σ i σ j ) {\displaystyle \rho _{ij}=M_{ij}^{\beta }/(\sigma _{i}\sigma _{j})} . These error estimates reflect only random errors in the measurements. The true uncertainty in the parameters is larger due to the presence of systematic errors, which, by definition, cannot be quantified. Note that even though the observations may be uncorrelated, the parameters are typically correlated.

### Parameter confidence limits

[edit]

Main article: Confidence interval

It is often assumed, for want of any concrete evidence but often appealing to the central limit theorem—see Normal distribution#Occurrence and applications—that the error on each observation belongs to a normal distribution with a mean of zero and standard deviation  σ {\displaystyle \sigma } . Under that assumption the following probabilities can be derived for a single scalar parameter estimate in terms of its estimated standard error  s e β {\displaystyle se_{\beta }} (given here):

* 68% that the interval  β ^ ± s e β {\displaystyle {\hat {\beta }}\pm se_{\beta }} encompasses the true coefficient value
* 95% that the interval  β ^ ± 2 s e β {\displaystyle {\hat {\beta }}\pm 2se_{\beta }} encompasses the true coefficient value
* 99% that the interval  β ^ ± 2.5 s e β {\displaystyle {\hat {\beta }}\pm 2.5se_{\beta }} encompasses the true coefficient value

The assumption is not unreasonable when n >> m. If the experimental errors are normally distributed the parameters will belong to a Student's t-distribution with n − m degrees of freedom. When n ≫ m Student's t-distribution approximates a normal distribution. Note, however, that these confidence limits cannot take systematic error into account. Also, parameter errors should be quoted to one significant figure only, as they are subject to sampling error.[4]

When the number of observations is relatively small, Chebychev's inequality can be used for an upper bound on probabilities, regardless of any assumptions about the distribution of experimental errors: the maximum probabilities that a parameter will be more than 1, 2, or 3 standard deviations away from its expectation value are 100%, 25% and 11% respectively.

### Residual values and correlation

[edit]

The residuals are related to the observations by  r ^ = y − X β ^ = y − H y = ( I − H ) y , {\displaystyle \mathbf {\hat {r}} =\mathbf {y} -X{\hat {\boldsymbol {\beta }}}=\mathbf {y} -H\mathbf {y} =(I-H)\mathbf {y} ,}

where H is the idempotent matrix known as the hat matrix:  H = X ( X T W X ) − 1 X T W , {\displaystyle H=X\left(X^{\textsf {T}}WX\right)^{-1}X^{\textsf {T}}W,}

and I is the identity matrix. The variance-covariance matrix of the residuals, M r is given by  M r = ( I − H ) M ( I − H ) T . {\displaystyle M^{\mathbf {r} }=(I-H)M(I-H)^{\textsf {T}}.}

Thus the residuals are correlated, even if the observations are not.

When  W = M − 1 {\displaystyle W=M^{-1}} ,  M r = ( I − H ) M . {\displaystyle M^{\mathbf {r} }=(I-H)M.}

The sum of weighted residual values is equal to zero whenever the model function contains a constant term. Left-multiply the expression for the residuals by XT WT:  X T W r ^ = X T W y − X T W X β ^ = X T W y − ( X T W X ) ( X T W X ) − 1 X T W y = 0 . {\displaystyle X^{\textsf {T}}W{\hat {\mathbf {r} }}=X^{\textsf {T}}W\mathbf {y} -X^{\textsf {T}}WX{\hat {\boldsymbol {\beta }}}=X^{\textsf {T}}W\mathbf {y} -\left(X^{\rm {T}}WX\right)\left(X^{\textsf {T}}WX\right)^{-1}X^{\textsf {T}}W\mathbf {y} =\mathbf {0} .}

Say, for example, that the first term of the model is a constant, so that  X i 1 = 1 {\displaystyle X_{i1}=1} for all i. In that case it follows that  ∑ i m X i 1 W i r ^ i = ∑ i m W i r ^ i = 0. {\displaystyle \sum _{i}^{m}X_{i1}W_{i}{\hat {r}}_{i}=\sum _{i}^{m}W_{i}{\hat {r}}_{i}=0.}

Thus, in the motivational example, above, the fact that the sum of residual values is equal to zero is not accidental, but is a consequence of the presence of the constant term, α, in the model.

If experimental error follows a normal distribution, then, because of the linear relationship between residuals and observations, so should residuals,[5] but since the observations are only a sample of the population of all possible observations, the residuals should belong to a Student's t-distribution. Studentized residuals are useful in making a statistical test for an outlier when a particular residual appears to be excessively large.

## See also

[edit]

* Iteratively reweighted least squares
* Heteroscedasticity-consistent standard errors
* Weighted mean

## References

[edit]

1. ^ "Weighted regression".
2. ^ "Visualize a weighted regression".
3. ^ a b Strutz, T. (2016). "3". Data Fitting and Uncertainty (A practical introduction to weighted least squares and beyond). Springer Vieweg. ISBN 978-3-658-11455-8.
4. ^ Mandel, John (1964). The Statistical Analysis of Experimental Data. New York: Interscience.
5. ^ Mardia, K. V.; Kent, J. T.; Bibby, J. M. (1979). Multivariate analysis. New York: Academic Press. ISBN 0-12-471250-9.

* v
* t
* e

Least squares and regression analysis

Computational statistics|

* Least squares
* Linear least squares
* Non-linear least squares
* Iteratively reweighted least squares

Correlation and dependence|

* Pearson product-moment correlation
* Rank correlation (Spearman's rho
* Kendall's tau)
* Partial correlation
* Confounding variable

Regression analysis|

* Ordinary least squares
* Partial least squares
* Total least squares
* Ridge regression

Regression as a
statistical model|

| Linear regression|

* Simple linear regression
* Ordinary least squares
* Generalized least squares
* Weighted least squares
* General linear model

|

Predictor structure|

* Polynomial regression
* Growth curve (statistics)
* Segmented regression
* Local regression

Non-standard|

* Nonlinear regression
* Nonparametric
* Semiparametric
* Robust
* Quantile
* Isotonic

Non-normal errors|

* Generalized linear model
* Binomial
* Poisson
* Logistic

Decomposition of variance|

* Analysis of variance
* Analysis of covariance
* Multivariate AOV

Model exploration|

* Stepwise regression
* Model selection
* Mallows's Cp
* AIC
* BIC
* Model specification
* Regression validation

Background|

* Mean and predicted response
* Gauss–Markov theorem
* Errors and residuals
* Goodness of fit
* Studentized residual
* Minimum mean-square error
* Frisch–Waugh–Lovell theorem

Design of experiments|

* Response surface methodology
* Optimal design
* Bayesian design

Numerical approximation|

* Numerical analysis
* Approximation theory
* Numerical integration
* Gaussian quadrature
* Orthogonal polynomials
* Chebyshev polynomials
* Chebyshev nodes

Applications|

* Curve fitting
* Calibration curve
* Numerical smoothing and differentiation
* System identification
* Moving least squares

* Regression analysis category
* Statistics category
* Mathematics portal
* Statistics outline
* Statistics topics

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template