regression - Python Statsmodels QuantReg Intercept -
problem setup in statsmodels quantile regression problem, least absolute deviation summary output shows intercept. in example, using formula
from __future__ import print_function import patsy import numpy np import pandas pd import statsmodels.api sm import statsmodels.formula.api smf import matplotlib.pyplot plt statsmodels.regression.quantile_regression import quantreg data = sm.datasets.engel.load_pandas().data mod = smf.quantreg('foodexp ~ income', data) res = mod.fit(q=.5) print(res.summary()) quantreg regression results ============================================================================== dep. variable: foodexp pseudo r-squared: 0.6206 model: quantreg bandwidth: 64.51 method: least squares sparsity: 209.3 date: fri, 09 oct 2015 no. observations: 235 time: 15:44:23 df residuals: 233 df model: 1 ============================================================================== coef std err t p>|t| [95.0% conf. int.] ------------------------------------------------------------------------------ intercept 81.4823 14.634 5.568 0.000 52.649 110.315 income 0.5602 0.013 42.516 0.000 0.534 0.586 ============================================================================== condition number large, 2.38e+03. might indicate there strong multicollinearity or other numerical problems.
the question
how can achieve summary output intercept
without using statsmodels.formula.api smf
formula approach?
of course, put question together, figured out. rather delete it, i'll share in case out there ever runs across this.
as suspected, needed add_constant() wasn't sure how. doing dumb , adding constant y (endog) variable instead of x (exog) variable.
the answer
from __future__ import print_function import patsy import numpy np import pandas pd import statsmodels.api sm import matplotlib.pyplot plt statsmodels.regression.quantile_regression import quantreg data = sm.datasets.engel.load_pandas().data data = sm.add_constant(data) mod = quantreg(data['foodexp'], data[['const', 'income']]) res = mod.fit(q=.5) print(res.summary()) quantreg regression results ============================================================================== dep. variable: foodexp pseudo r-squared: 0.6206 model: quantreg bandwidth: 64.51 method: least squares sparsity: 209.3 date: fri, 09 oct 2015 no. observations: 235 time: 22:24:47 df residuals: 233 df model: 1 ============================================================================== coef std err t p>|t| [95.0% conf. int.] ------------------------------------------------------------------------------ const 81.4823 14.634 5.568 0.000 52.649 110.315 income 0.5602 0.013 42.516 0.000 0.534 0.586 ============================================================================== condition number large, 2.38e+03. might indicate there strong multicollinearity or other numerical problems.
as fyi, find interesting add_constant()
adds column of 1
s data. more information add_constant()
can found here.
Comments
Post a Comment