using ols from statsmodels.formula.api - how to remove constant term?
Asked Answered
B

1

7

I'm following this first example in statsmodels tutorial:

http://statsmodels.sourceforge.net/devel/

How do I specify not to use constant term for linear fit in ols?

# Fit regression model (using the natural log of one of the regressors)
results = smf.ols('Lottery ~ Literacy + np.log(Pop1831)', data=dat).fit()
Beanfeast answered 4/4, 2016 at 18:13 Comment(0)
P
14

As shown here in the section on Operators, you can use "-1" in the formula string to remove an intercept term:

results = smf.ols('Lottery ~ Literacy + np.log(Pop1831) - 1', data=dat).fit()
Parkerparkhurst answered 4/4, 2016 at 18:37 Comment(1)
Another option is to add zero to the formula.Segmentation

© 2022 - 2024 — McMap. All rights reserved.