What could explain the difference in intercepts between statsmodel OLS regression and also seaborn lmplot?
My statsmodel code:
X = mmm_ma[['Xvalue']]
Y = mmm_ma['Yvalue']
model2 = sm.OLS(Y,sm.add_constant(X), data=mmm_ma)
model_fit = model2.fit()
model_fit.summary()
My seaborn lmplot code:
sns.lmplot(x='Xvalue', y='Yvalue', data=mmm_ma)
My statsmodel intercept is 28.9775 and my seaborn lmplot's intercept is around 45.5.
Questions
- Should the intercepts be the same?
- Why might explain why these are different? (can I change some code to make it equal)
- Is there a way to achieve a plot similar to seaborn lmplot but using the exact regression results to ensure they align?
Edit
@Massoud thanks for posting that. I think I have realised what is the problem. My x-values range between 1400 to 2600 and y-values range from 40 to 70. So using seaborn lmplot, it just plots the regression and the intercept is based on the lowest range X value - which is an intercept of 46.
However for statsmodel OLS, it keeps the line going until X = 0, which is why I get an intercept of 28 or so.
So I guess the question is there a way to continue the trend line using seaborn to go all the way until x = 0.
I tried changing the axis but it doesn't seem to extend the line.
axes = lm.axes
axes[0,0].set_xlim(0,)