The weighted least squares (WLS) method is a generalization of the ordinary least squares (OLS) method to account for heteroscedasticity, or situations where the residuals do not have constant variance across all levels of the independent variable(s). In WLS, each observation is assigned a weight that reflects the reliability or precision of its variance. The weights are typically the inverse of the variance of the observations.
Here's the formula for the weighted least squares estimator for a linear regression model:
Given a linear model:
[ y_i = \beta_0 + \beta_1 x_{i1} + \beta_2 x_{i2} + \ldots + \beta_k x_{ik} + \varepsilon_i ]
where ( y_i ) is the dependent variable, ( x_{i1}, x_{i2}, \ldots, x_{ik} ) are the independent variables, ( \beta_0, \beta_1, \ldots, \beta_k ) are the parameters to be estimated, and ( \varepsilon_i ) is the error term for the ( i )-th observation.
In WLS, each observation has an associated weight ( w_i ). The WLS estimator minimizes the following weighted sum of squared residuals:
[ Q(\beta) = \sum_{i=1}^{n} w_i (y_i - \beta_0 - \beta_1 x_{i1} - \beta_2 x_{i2} - \ldots - \beta_k x_{ik})^2 ]
To find the WLS estimators ( \hat{\beta} ), you take the derivative of ( Q(\beta) ) with respect to each ( \beta_j ), set the derivative equal to zero, and solve for ( \beta_j ). This typically results in a system of normal equations that can be written in matrix form as:
[ (X^T W X) \hat{\beta} = X^T W y ]
where:
- ( X ) is the design matrix containing the independent variables (including a column of ones for the intercept term ( \beta_0 )),
- ( W ) is a diagonal matrix of weights with ( w_i ) on the diagonal,
- ( y ) is the vector of observed dependent variable values,
- ( \hat{\beta} ) is the vector of estimated parameters.
To solve for ( \hat{\beta} ), you would typically compute:
[ \hat{\beta} = (X^T W X)^{-1} X^T W y ]
This gives you the estimated parameters that minimize the weighted sum of squared residuals. Note that when all ( w_i ) are equal (e.g., ( w_i = 1 )), the WLS estimator reduces to the OLS estimator.