statsmodels/statsmodels-formula-power-term
| Pack | Severity | Fix | Versions |
|---|---|---|---|
| statsmodels | warning | unsafe, with xpd check --fix --unsafe-fixes |
All versions |
In a statsmodels OLS formula, Patsy and Formulaic use ** to expand interactions.
For a single predictor, x**2 gives the same term as x. In both engines,
y ~ x + x**2 produced two columns and y ~ x + I(x**2) produced three.
smf.ols("y ~ x + x**2", data)smf.ols("y ~ x + I(x**2)", data)What the rule reports
Section titled “What the rule reports”The rule checks additive formula literals in ols and OLS.from_formula,
including raw strings and formulas with simple parenthesized terms. It
reports a standalone predictor name raised to a literal integer of at least
two. The edit preserves existing transforms such as I(z**2) and
interaction expansions such as (a + b)**2.
How to fix it
Section titled “How to fix it”Wrap a numeric power in I(...). Use xpd check --fix --unsafe-fixes
to apply the edit. It changes the design matrix.
Patsy formula operators · Formulaic grammar
Diagnostic message
Section titled “Diagnostic message”In a statsmodels OLS formula, x**2 expands interactions and does not square x. Write I(x**2) for a quadratic term.See all rules in the statsmodels pack.