When trying to run the below code predict, it gives me an error saying interval arg should be none or confidence and so I am wondering if there is a way to get prediction interval using quantile regression?
Note: If I replace the rq with lm I am able to find the prediction interval but, I want to find it using rq.
#mycode:
library(quantreg)
mydata <- read.csv("C:\\Users\\gokul\\Desktop\\Book4.csv")
attach(mydata)
summary(mydata)
mod = rq(y~q) # y is my dependent and q is my independent variables
summary(mod)
predict(mod, data.frame(q), interval = "prediction",level = 0.10)
Snippet of CSV file:
dput(head(mydata,10))
structure(list(y = c(71143L, 68061L, 66603L, 66907L, 69073L,
72901L, 77521L, 81728L, 84842L, 87877L), q = c(71416.79329, 68003.59226,
66533.66142, 66620.44529, 68640.60953, 72945.13676, 77743.82153,
81604.52442, 84887.47483, 87904.33486)), row.names = c(NA, 10L
), class = "data.frame")
Sure, just use the 0.05 and 0.95 quantile functions. That will give you the 90% prediction limits. Change 0.05 and 0.95 to 0.025 and 0.975 if you want 95% limits. Here is some R code.
Here is the result: