I am using quantreg
package to calculate quantile regressions. I am fitting regressions for a number of taus and would like to calculate predicted values and 95% confidence intervals.
The problem is that the function predict.qr
seems not to allow for more than one quantile if you add confidence limits. So far, I solved the problem using loops but that makes my code terribly long.
Minimal example:
1) one quantile (0.5) works fine
# prediction data set
pred.df <- data.frame(disp = 150:160)
fit <- rq(mpg ~ disp, data = mtcars, tau = 0.5)
predict.rq(fit,
newdata = pred.df,
interval = "confidence")
2) more than one quantile and only predicted values (no ci) also works fine
fit <- rq(mpg ~ disp, data = mtcars, tau = c(0.5, 0.6))
predict.rq(fit,
newdata = pred.df)
3) when more than one quantile (0.5, 0.75) and ci, it does not work any more
fit <- rq(mpg ~ disp, data = mtcars, tau = c(0.5, 0.6))
predict.rq(fit,
newdata = pred.df,
interval = "confidence")
Therefore my question: is it possible to get predicted values and confidence intervals for more than one quantile regression using only predict.rq and avoid loops?