Repository navigation
Description
QuantReg.fit() defaults to vcov="robust", which the docstring describes as heteroskedasticity robust standard errors. But the "robust" covariance uses a single kernel estimate of the error density, fhat0, for all observations:
d = np.where(e > 0, (q / fhat0) ** 2, ((1 - q) / fhat0) ** 2)
vcov = xtxi @ X'DX @ xtxiSince E[d_i | x_i] = q(1-q)/fhat0^2, this converges to the iid covariance and carries no information about heteroskedasticity. At q=0.5 every d_i is the same, so "robust" equals "iid" to every digit. Heteroskedastic errors are the usual reason to fit a quantile regression, so the default standard errors there are too small.
import statsmodels.api as sm
from statsmodels.regression.quantile_regression import QuantReg
data = sm.datasets.engel.load_pandas().data
mod = QuantReg.from_formula("foodexp ~ income", data)
print(mod.fit(q=0.5).bse.values) # default, vcov="robust"
print(mod.fit(q=0.5, vcov="iid").bse.values)
print(mod.fit(q=0.5, kernel="gau").bse.values)
print(mod.fit(q=0.5, kernel="gau", vcov="iid").bse.values)Output on main (0dfcd99):
[1.46344744e+01 1.31756229e-02]
[1.46344744e+01 1.31756229e-02]
[1.83593608e+01 1.65291905e-02]
[1.83593608e+01 1.65291905e-02]
R quantreg 6.1, same data (summary(rq(foodexp ~ income, tau = q, data = engel), se = s)), standard errors of (Intercept, income):
| q | statsmodels default | R se="ker" |
R se="nid" |
|---|---|---|---|
| 0.25 | 18.47, 0.0174 | 24.16, 0.0295 | 21.39, 0.0291 |
| 0.5 | 14.63, 0.0132 | 30.22, 0.0373 | 19.25, 0.0283 |
| 0.75 | 12.51, 0.0110 | 29.12, 0.0362 | 16.31, 0.0232 |
In a simulation with y = 1 + x + (0.5 + x) e, n = 400, the 95% interval for the slope at the median covered 90% with the default (same as iid), against 97% with R's ker and 93% with nid. With stronger heteroskedasticity (sd = 0.2 + x^2) the default covered 75%.
The formula has been there since QuantReg was added in 2013 (it follows Greene, Econometric Analysis, 6th ed.).
Proposed fix: estimate the density at each observation with the kernel and bandwidth the fit already computes, the Powell (1991) sandwich in Koenker (2005, Section 3.4):
fhat = kernel(e / h) / h
xfxi = pinv(X' diag(fhat) X)
vcov = q * (1 - q) * xfxi @ X'X @ xfxiWith kernel="gau" this gives exactly R's se="ker" on the Engel data (24.16391949 / 0.02954882 at q=0.25, 30.21531585 / 0.03731704 at q=0.5, 29.11875602 / 0.03621607 at q=0.75). The default numbers of QuantReg would change, so I wanted to check here first. Would you prefer fixing "robust" in place, or adding the sandwich under a new name and changing the default later? I have a branch with the in-place fix and tests against R, and can open the PR.
Activity
bhaskargurram-ai commentedon Nov 17, 2026
@bashtage, before I open the PR, which would you prefer?
Fix vcov="robust" in place, with a release note that the default QuantReg standard errors change, or
Add the Powell sandwich under a new name (for example vcov="kernel"), keep "robust" as it is for now, and switch the default later with a FutureWarning.
I have a branch with option 1 and tests against R quantreg 6.1 (se="ker" matches to 9 digits on the Engel data at q = 0.25, 0.5 and 0.75). I can switch it to option 2 if you’d rather not change the default yet.