Skip to content

statsmodels/ols-ignored-weights

Pack Severity Fix Versions
statsmodels error none, edit by hand All versions

Statsmodels OLS warns and ignores weights. The fitted coefficients are those of an unweighted regression even when the weights vary across observations.

sm.OLS(y, X, weights=weights).fit()
sm.WLS(y, X, weights=weights).fit()

The rule checks an explicit weights keyword on OLS, OLS.from_formula, and the formula API's ols.

Use WLS or the formula API's wls if the weights are proportional to inverse observation variances. Drop the keyword if the regression should be unweighted. In a 0.15.0 fit with nonconstant weights, the OLS slope stayed at 1.04345 with or without the keyword and changed to 0.97627 with WLS.

OLS and WLS implementation

Statsmodels OLS ignores weights. Use WLS with inverse-variance weights for a weighted fit, or remove weights for an unweighted fit.

See all rules in the statsmodels pack.