user6883405
user6883405

Reputation: 403

Explicitly set intercept term in statsmodels

Is there a way to explicitly define what the intercept term should be in stats models OLS? I do not see it as a parameter. One work around I found on a different question was to exclude the constant from the model and then subtract the desired intercept from the target:

somedata = pd.DataFrame(np.random.random((n_samples, 3)), columns = ['x', 'y', 'z'])
somedata['s'] = somedata['z'] - predefined_intercept
results = ols(formula="s ~ x + y - 1 ", data=somedata).fit()
print(results.summary())

Upvotes: 1

Views: 301

Answers (1)

Kevin S
Kevin S

Reputation: 2803

That is the right way. Basically y - c ~ a + b - 1 where c is your desired intercept.

Upvotes: 1

Related Questions