使用rq函数计算R中分位数回归的95%置信区间 [英] Calculating 95% confidence intervals in quantile regression in R using rq function

查看:410
本文介绍了使用rq函数计算R中分位数回归的95%置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望获得分位数回归的回归系数的95%置信区间.您可以使用R中quantreg包的rq函数(与OLS模型相比)来计算分位数回归:

I would like to get 95% confidence intervals for the regression coefficients of a quantile regression. You can calculate quantile regressions using the rq function of the quantreg package in R (compared to an OLS model):

library(quantreg)
LM<-lm(mpg~disp, data = mtcars)
QR<-rq(mpg~disp, data = mtcars, tau=0.5)

使用confint函数,我能够获得线性模型的95%置信区间:

I am able to get 95% confidence intervals for the linear model using the confint function:

confint(LM)

当我使用分位数回归时,我了解以下代码会产生自举标准错误:

When I use quantile regression I understand that the following code produces bootstrapped standard errors:

summary.rq(QR,se="boot")

但是实际上我想要的是95%的置信区间.就是说,这样的解释:概率为95%,间隔包括真实系数".当我使用summary.lm()计算标准错误时,我将乘以SE * 1.96并得到与confint()类似的结果.但是,使用自举标准错误是不可能的. 那么我的问题是如何获得分位数回归系数的95%置信区间?

But actually I would like something like 95% confidence intervals. That is, something to interprete like: "with a probability of 95%, the interval [...] includes the true coefficient". When I calculate standard errors using summary.lm() I would just multiply SE*1.96 and get similar results as from confint(). But this is not possible using bootstrapped standard errors. So my question is how get 95% confidence intervals for quantile regression coefficients?

推荐答案

您可以直接使用boot.rq函数来自举系数:

You can use the boot.rq function directly to bootstrap the coefficients:

x<-1:50
y<-c(x[1:48]+rnorm(48,0,5),rnorm(2,150,5))

QR <- rq(y~x, tau=0.5)
summary(QR, se='boot')

LM<-lm(y~x)

QR.b <- boot.rq(cbind(1,x),y,tau=0.5, R=10000)

t(apply(QR.b$B, 2, quantile, c(0.025,0.975)))
confint(LM)


plot(x,y)
abline(coefficients(LM),col="green")
abline(coefficients(QR),col="blue")

for(i in seq_len(nrow(QR.b$B))) {
  abline(QR.b$B[i,1], QR.b$B[i,2], col='#0000ff01')
}

您可能希望使用引导程序包来计算除百分位数间隔以外的间隔.

You may want to use the boot package to compute intervals other than the percentile interval.

这篇关于使用rq函数计算R中分位数回归的95%置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆