linearmodels/formula-power-term
| Rule | formula-power-term |
|---|---|
| Pack | linearmodels |
| Severity | error |
| Fix | unsafe, with xpd check --fix --unsafe-fixes |
| Library versions | every version |
A formula reads ** as a power of interactions, so exper**2 is just exper, with no error. Write I(exper**2) for the squared values.
model = IV2SLS.from_formula("lwage ~ 1 + exper + exper**2", data)model = IV2SLS.from_formula("lwage ~ 1 + exper + I(exper**2)", data)What the rule reports
Section titled “What the rule reports”The rule reports a term that is a name, ** and a number, such as exper**2, in a formula of any
model. A formula reads ** as a power of interactions, so exper**2 is exper. The squared values
need I(exper**2).
How to fix it
Section titled “How to fix it”xpd check --fix --unsafe-fixes applies the fixes of this rule. Check the result, because an unsafe fix can change what the code does.
The unsafe fix writes I(exper**2) for exper**2, which changes the model on purpose.
On 7.1 and 7.0 the first formula gave a model with the columns Intercept and exper on IV2SLS and on PooledOLS, with no error, and the second gave three columns. The README of linearmodels itself has exper + exper ** 2 in its first example, which fits a model with the columns Intercept, exper and educ. (a + b)**2, which is the use the operator is for, is left alone.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
A formula reads ** as a power of interactions, not of the values, so a term such as exper**2 in $F is exper itself. "lwage ~ 1 + exper + exper**2" gave a model with the columns Intercept and exper, with no error. Write I(exper**2) for the squared values.Browse the other rules of the linearmodels pack.