Skip to content

FAQ/BUG: Quantile regression: small sample, bse are nan #2483

Open

Description

@josef-pkt

found while investigating #2377 (with the proposed fix replacing sign by >= )

the standard errors are nan, and there are RuntimeWarnings related to the kernel estimation.

What's the minimum size for the kernel calculation of cov_params?
the following needs to be smaller than q, e.g. q = 0.5
chamberlain and bofinger require at least 4 observations, hall_sheather (hsheather) needs 8

>>> import statsmodels.regression.quantile_regression as qr
>>> qr.chamberlain(4, 0.5)
0.48999099613501351
>>> qr.hall_sheather(8, 0.5)
0.48577951310258921
>>> qr.bofinger(4, 0.5)
0.49086103316125856
import numpy as np
from statsmodels.api import QuantReg

X = np.array([[1, 0], [0, 1], [0, 2.1]], dtype=np.float64)
y = np.array([0, 1, 2], dtype=np.float64)

res = QuantReg(y, X).fit(0.5)

X = np.array([[1, 0], [0, 1], [0, 2.1], [0, 3.1]], dtype=np.float64)
y = np.array([0, 1, 2, 3], dtype=np.float64)

res = QuantReg(y, X).fit(0.5)

prints:

m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34\statsmodels\regression\quantile_regression.py:238: RuntimeWarning: invalid value encountered in less_equal
  kernels['epa'] = lambda u: 3. / 4 * (1-u**2) * np.where(np.abs(u) <= 1, 1, 0)
m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34\statsmodels\regression\quantile_regression.py:208: RuntimeWarning: invalid value encountered in double_scalars
  d = np.where(e > 0, (q/fhat0)**2, ((1-q)/fhat0)**2)
>>> print(res.summary())
                         QuantReg Regression Results                          
==============================================================================
Dep. Variable:                      y   Pseudo R-squared:               0.9839
Model:                       QuantReg   Bandwidth:                         nan
Method:                 Least Squares   Sparsity:                          nan
Date:                Mon, 29 Jun 2015   No. Observations:                    4
Time:                        10:32:09   Df Residuals:                        2
                                        Df Model:                            2
==============================================================================
                 coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
x1                  0        nan        nan        nan           nan       nan
x2             0.9677        nan        nan        nan           nan       nan
==============================================================================
m:\josef_new\eclipse_ws\statsmodels\statsmodels_py34\statsmodels\stats\stattools.py:72: UserWarning: omni_normtest is not valid with less than 8 observations; 4 samples were given.
  "samples were given." % int(n))
C:\programs\WinPython-64bit-3.4.3.1\python-3.4.3.amd64\lib\site-packages\scipy\stats\_distn_infrastructure.py:1728: RuntimeWarning: invalid value encountered in greater
  cond1 = (scale > 0) & (x > self.a) & (x < self.b)
C:\programs\WinPython-64bit-3.4.3.1\python-3.4.3.amd64\lib\site-packages\scipy\stats\_distn_infrastructure.py:1728: RuntimeWarning: invalid value encountered in less
  cond1 = (scale > 0) & (x > self.a) & (x < self.b)
C:\programs\WinPython-64bit-3.4.3.1\python-3.4.3.amd64\lib\site-packages\scipy\stats\_distn_infrastructure.py:1729: RuntimeWarning: invalid value encountered in less_equal
  cond2 = cond0 & (x <= self.a)

Activity

  1. added this to the 0.8 milestone on Jun 29, 2015
  2. josef-pkt commented on Jun 29, 2015

    @josef-pkt
    MemberAuthor

    The last part in the bandwidth calculation using norm.ppf doesn't protect for h > q (so prob is outside [0,1].
    AFAICS: this imposes a lower bound on nobs n for chamberlain
    correction chamberlain works even if nobs=4. I got the nans with the default hsheather

    h = min(np.std(endog),
                    iqre / 1.34) * (norm.ppf(q + h) - norm.ppf(q - h))
    
    p q
    0.5
    (Pdb) (norm.ppf(q + h0) - norm.ppf(q - h0))
    nan
    (Pdb) h0
    0.61204383416563446
    
  3. changed the title [-]BUG: Quantile regression: small sample, bse are nan[/-] [+]FAQ/BUG: Quantile regression: small sample, bse are nan[/+] on Jun 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions