Calculation of 95% confidence intervals in quantile regression in R using the rq function

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

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

I can get 95% confidence intervals for a linear model using the confint function:

 confint(LM) 

When I use quantile regression, I understand that the following code creates boot standard errors:

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

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

+5
source share
2 answers

You can use the boot.rq function directly to load 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 can use the boot package to calculate intervals other than the percentile interval.

+4
source

You can also just extract vcov from the object by setting covariance=TRUE . It comes down to using standard standard errors in your CI:

 vcov.rq <- function(x, se = "iid") { vc <- summary.rq(x, se=se, cov=TRUE)$cov dimnames(vc) <- list(names(coef(x)), names(coef(x))) vc } confint(QR) 

But yes, the best way to do this is to use a student bootstrap.

+1
source

All Articles