Python Statsmodels QuantReg Intercept

Setting up the problem In the problem of statsmodels Quantile Regression, their summary of the least absolute deviation shows Intercept. In this example, they use the formula

from __future__ import print_function
import patsy
import numpy as np
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
from 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
==============================================================================

The condition number is large, 2.38e+03. This might indicate that there are
strong multicollinearity or other numerical problems.

Question

How can I get the final output with Intercept no using the formula statsmodels.formula.api as smf?

+4
source share
1 answer

Of course, when I asked this question together, I realized this. Instead of deleting it, I will share it if one of them ever comes across this.

, add_constant(), , . - Y (endog) X (exog).

from __future__ import print_function
import patsy
import numpy as np
import pandas as pd
import statsmodels.api as sm
import matplotlib.pyplot as plt
from 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
==============================================================================

The condition number is large, 2.38e+03. This might indicate that there are
strong multicollinearity or other numerical problems.

FYI , add_constant() 1 . add_constant() .

+6

Source: https://habr.com/ru/post/1611056/


All Articles