question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

quantreg: exception with singular exog

See original GitHub issue

I’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:closed
  • Created 8 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
hpahkalacommented, Nov 16, 2018

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.

0reactions
josef-pktcommented, Sep 6, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found