WLS — Weighted Least Squares
WLS (Weighted Least Squares) is a variant of OLS used when there is heteroskedasticity whose structure is known (or can be estimated). WLS assigns weights inversely proportional to the error variance to restore estimation efficiency.
Use WLS when the error variance is non-constant but has a known structure (e.g., variance proportional to a variable). If you only need robust inference without knowing the structure, use OLS + robust standard errors.
Model specification
WLS minimizes the weighted sum of squared residuals with weights :
The optimal weight is the inverse of the error variance . When all are equal, WLS reduces to OLS.
Assumptions & notes
- You must know or correctly estimate the variance structure ; wrong weights can make results worse than OLS.
- If the variance must be estimated from data, you have FGLS (Feasible GLS).
- Still requires exogeneity () as in OLS.
Running in EcoLab
- Modeling module → Classical linear regression family → WLS.
- Select , the variables, and the weight variable/rule (e.g., , ).
- Run and compare with OLS in the Estimation tab; export the replication code.
Input / output example
Input (illustrative): household spending on income; variance grows with income ⇒ weights .
Output (format, illustrative figures — not real results): coefficients similar to OLS but with smaller SE (more efficient) when the weights are correct.
Replication code
- Stata
- R
- Python
* ---- WLS: Weighted Least Squares ----
* Load data (illustrative)
use "household_data.dta", clear
* WLS with analytical weights (weight = 1/income)
regress spending x1 x2 [aweight=w]
* Compare with OLS
regress spending x1 x2
# ---- WLS: Weighted Least Squares ----
# Load data (illustrative)
df <- read.csv("household_data.csv")
# WLS with weights inversely proportional to variance
model_wls <- lm(y ~ x1 + x2, weights = w, data = df)
summary(model_wls)
# Compare with OLS
model_ols <- lm(y ~ x1 + x2, data = df)
summary(model_ols)
# ---- WLS: Weighted Least Squares ----
import pandas as pd
import statsmodels.api as sm
# Load data (illustrative)
df = pd.read_csv("household_data.csv")
X = sm.add_constant(df[["x1", "x2"]])
y = df["y"]
# WLS: weights = 1/sigma^2
sigma2 = df["income"] # variance proportional to income
model_wls = sm.WLS(y, X, weights=1 / sigma2).fit()
print(model_wls.summary())
Limitations
- Very sensitive to incorrect weight choice.
- When unsure about the variance structure, prefer OLS + robust SE or GLS/FGLS.
Video tutorial
Video Tutorial: Running WLS in EcoLab
See also
- OLS · GLS · Model catalog