quantreg: exception with singular exog
See original GitHub issueI’m trying to run quantile regression with a number of variables. It appears quantreg.fit()
will not allow more than 8 variables/columns to be included in the formula.
import pandas as pd
import statsmodels.formula.api as smf
from statsmodels.regression.quantile_regression import QuantReg
d = pd.read_csv('<path-to-data>')
#7 vars (lag and sunday through friday), seems to work fine
qr = smf.quantreg('load ~ lag + su + m + t + w + th + f', d')
qm = qr.fit(q=0.5)
#8 vars (lag and sunday through saturday), throws error
qr = smf.quantreg('load ~ lag + su + m + t + w + th + f + s', d')
qm = qr.fit(q=0.5)
Here’s the trace:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-17-f2074b49225f> in <module>()
---> 32 qm = qr.fit(q=.5)
.../statsmodels/regression/quantile_regression.py in fit(self, q, vcov, kernel, bandwidth, max_iter, p_tol, **kwargs)
177 resid = np.abs(resid)
178 xstar = exog / resid[:, np.newaxis]
--> 179 diff = np.max(np.abs(beta - beta0))
180 history['params'].append(beta)
181 history['mse'].append(np.mean(resid*resid))
ValueError: operands could not be broadcast together with shapes (9,) (8,)
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
StatsModel quantile regression ValueError - Stack Overflow
I think your design matrix is singular, i.e. this does not hold for your data: np.linalg.matrix_rank(model.exog) == model.exog.shape[1].
Read more >Source code for statsmodels.regression.quantile_regression
#!/usr/bin/env python ''' Quantile regression model Model ... T, exog)) else: raise Exception("vcov must be 'robust' or 'iid'") lfit ...
Read more >operands could not be broadcast together with shapes (3,) (2,)
Your design matrix exog has fewer rows than columns and, therefore, does not have full column rank. QuantReg needs a full rank, non-singular...
Read more >quantreg: Quantile Regression
Description Estimation and inference methods for models for conditional quantile functions: Linear and nonlinear parametric and non-parametric ( ...
Read more >ego.psych.mcgill.ca/labs/mogillab/anaconda2/lib/py...
def __init__(self, endog, exog, **kwargs): super(QuantReg, self). ... 'par'] if kernel not in kern_names: raise Exception("kernel must be ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I second more informative warning or message. I had collinearity problem in my data but started to debug the issue from the wrong place due to the message.
fixed in #7694 based on PR #6397
The behavior now is that it doesn’t raise on singular exog, but instead provides a pinv solution.