0

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")
Gokul
  • 41
  • 7
  • 1
    Read the manual: https://www.rdocumentation.org/packages/quantreg/versions/5.67/topics/predict.rq The correct value for the `interval` argument is `"confidence"`, not `"prediction"`. –  Sep 25 '20 at 19:48
  • @Jean-ClaudeArbaut yes I know but, I want to be able to find it for quantile regression. I want a method to be find prediction interval in quantile regression rather than linear model – Gokul Sep 25 '20 at 20:18
  • Read again..... –  Sep 25 '20 at 20:25

1 Answers1

3

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

BigBendRegion
  • 210
  • 1
  • 5
  • Is it possible to obtain lower and upper bound values for q(my predicted value) instead of a graph. I am using y~q and I need to be able to obtain upper and lower bounds for q. I am considering y(actual) as my dependent and q(predicted) as my independent variables. – Gokul Sep 28 '20 at 21:08
  • Yes, the data values in the "Lower" and "Upper" objects in my code are exactly those. The predicted value itself is irrelevant, but I guess you will use the .50 quantile. – BigBendRegion Sep 28 '20 at 23:52