Reputation: 7999
I have the following ouput from a Pandas pooled OLS regression. The only problem is that I'm not sure where the intercept is. In a regression there is always an intercept that is usually listed before the exogenous variables, i.e. Y = a + ßx1 + ßx2 + error_term
I do not see it in my regression. I used the suggestion from ayhan X = add_constant(X)
but somehow I get the feeling that I am messing something up (in an obvious way) with the syntax. I know that this is not rocket science. Can someone tell me what I am missing?
import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import statsmodels.formula.api as sm
from sklearn.linear_model import LinearRegression
import scipy, scipy.stats
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
from statsmodels.api import add_constant
X = add_constant(X)
Y = df['billsum_support']
X = df[['direct_expenditures','indirect_expenditures', 'years_exp', 'leg_totalbills',\
'log_diff_rgdp', 'unemployment', 'expendituresfor']]
result = sm.OLS( Y, X ).fit()
result.summary()
OLS Regression Results Dep. Variable: billsum_support R-squared: 0.663
Model: OLS Adj. R-squared: 0.663
Method: Least Squares F-statistic: 3932.
Date: Sun, 08 May 2016 Prob (F-statistic): 0.00
Time: 22:38:33 Log-Likelihood: -12561.
No. Observations: 12008 AIC: 2.513e+04
Df Residuals: 12002 BIC: 2.518e+04
Df Model: 6
Covariance Type: nonrobust
coef std err t P>|t| [95.0% Conf. Int.]
direct_expenditures 4.575e-05 4.02e-06 11.377 0.000 3.79e-05 5.36e-05
indirect_expenditures -2.147e-05 6.93e-06 -3.099 0.002 -3.5e-05 -7.89e-06
years_exp 0.0030 0.001 5.595 0.000 0.002 0.004
leg_totalbills 0.0052 0.000 11.160 0.000 0.004 0.006
log_diff_rgdp 1.0325 0.178 5.805 0.000 0.684 1.381
unemployment 0.1052 0.001 70.744 0.000 0.102 0.108
expendituresfor 2.428e-05 3.57e-06 6.797 0.000 1.73e-05 3.13e-05
Omnibus: 2994.033 Durbin-Watson: 0.837
Prob(Omnibus): 0.000 Jarque-Bera (JB): 19159.354
Skew: 1.042 Prob(JB): 0.00
Kurtosis: 8.827 Cond. No. 1.54e+16
Upvotes: 3
Views: 4856
Reputation:
You need to explicitly tell statsmodels to fit an intercept. Update your independent variables with statsmodels.api.add_constant
:
from statsmodels.api import add_constant
Y = df['billsum_support']
X = df[['direct_expenditures','indirect_expenditures', 'years_exp', 'leg_totalbills',\
'log_diff_rgdp', 'unemployment', 'expendituresfor']]
X = add_constant(X)
result = sm.OLS( Y, X ).fit()
Upvotes: 5