Is possible to find prediction interval using quantile regression?

906 views Asked by At

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")
1

There are 1 answers

2
BigBendRegion On

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.

n = 1000
beta0 = 2.1; beta1 = 0.7
set.seed(12345)
X = runif(n, 10, 20)
Y = beta0 + beta1*X + .4*X*rnorm(n)

library(quantreg)
fit.05 = rq(Y ~ X, tau = .05)
fit.95 = rq(Y ~ X, tau = .95)

Lower = fit.05$fitted.values
Upper = fit.95$fitted.values

plot(X,Y, main = "Scatterplot with 90% Prediction Limits")
points(X,Lower, pch=".", col="red")
points(X,Upper, pch=".", col="red")

Here is the result:

Scatterplot with 90% Limits