3

I am applying guantile regression for my data-set (using R). It is easy to produce the nice scatterplot-image with different quantile regression lines (taus <- c(0.05,0.25,0.75,0.95)).

Problem occurs when I want to produce p-values (in order to see statistical significance of each regression line) for each one of these quantiles. For median quantile (tau=0.5) this is not problematic, but when it comes to for example tau=0.25, I get following error message:

>QRmodel<-rq(y~x,tau=0.25,model=T)
>summary(QRmodel,se="nid")
Error in summary.rq(QRmodel, se = "nid") : tau - h < 0:  error in summary.rq

What could be the reason for this?

Also: Is it recommendable to mention p-values and coefficients regarding the results of quantile regression model or could it be enough to show just the plot-picture and discuss the results based on that picture?

Best regards, frustrated person

4

2 回答 2

8

了解在这类调试情况下发生了什么的一个好方法是找到引发错误的代码的相关部分。如果您在控制台输入“summary.rq”,您将看到函数summary.rq 的代码。浏览它,您会发现它使用“nid”方法计算 se 的部分,从以下代码开始:

else if (se == "nid") {
    h <- bandwidth.rq(tau, n, hs = hs)
    if (tau + h > 1) 
        stop("tau + h > 1:  error in summary.rq")
    if (tau - h < 0) 
        stop("tau - h < 0:  error in summary.rq")
    bhi <- rq.fit.fnb(x, y, tau = tau + h)$coef
    blo <- rq.fit.fnb(x, y, tau = tau - h)$coef

所以这里发生的是,为了计算 se,函数首先需要计算带宽 h,并且 quantreg 模型针对 tau +/- h 进行了重新拟合。对于接近 0 或 1 的 tau,增加或减去带宽“h”可能会导致 tau 低于 0 或大于 1,这是不好的,因此函数停止。

你有几个选择:

1.) 尝试不同的 se 方法(自举?)

2.) 自己修改 summary.rq 代码以强制它在带宽将 tau 超出范围的情况下使用 max(tau,0) 或 min(tau,1)。(这可能是一个坏主意的严重理论原因;除非您知道自己在做什么,否则不建议这样做。)

3.) 您可以尝试阅读计算这些 se 背后的理论,以便您更好地了解它们何时可以正常工作。这可能会解释为什么您会在 tau 值接近 0 或 1 时遇到错误。

于 2011-06-03T17:14:51.360 回答
0

尝试summary(QRmodel,se="boot")

看看帮助summary.rq吧!

于 2015-01-27T11:18:03.487 回答