statsmodels/ols-ignored-weights
| Rule | ols-ignored-weights |
|---|---|
| Pack | statsmodels |
| Severity | error |
| Fix | none, edit by hand |
| Library versions | every version |
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()What the rule reports
Section titled “What the rule reports”The rule checks an explicit weights keyword on OLS, OLS.from_formula,
and the formula API's ols.
How to fix it
Section titled “How to fix it”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.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
Statsmodels OLS ignores weights. Use WLS with inverse-variance weights for a weighted fit, or remove weights for an unweighted fit.Browse the other rules of the statsmodels pack.