I have the following linear regression:
import statsmodels.formula.api as sm
model = sm.ols(formula = 'a ~ b + c', data = data).fit()
I want to add a quadratic term for b in this model.
Is there a simple way to do this with statsmodels.ols
?
Is there a better package I should be using to achieve this?
The simplest way is
model = sm.ols(formula = 'a ~ b + c + I(b**2)', data = data).fit()
The I(...)
basically says "patsy, please stop being clever here and just let Python handle everything inside kthx". (More detailed explanation)