Reputation: 403
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
Reputation: 2803
That is the right way. Basically y - c ~ a + b - 1
where c is your desired intercept.
Upvotes: 1