Search code examples
rforecasting

Can I get confidence interval instead of prediction interval using forecast.Arima (package forecast)?


Hi I understand roughly the differences between confidence interval and prediction interval (see post from Rob Hyndman and the discussion on crossvalidated). And that prediction interval is much wider than confidence interval.

My question is can I get the confidence interval from forecast.Arima? Why is only prediction interval rather than confidence interval calculated from forecast? In the document of forecast:

forecast(object, h=10, level=c(80,95), fan=FALSE, lambda=NULL, 
    bootstrap=FALSE, npaths=5000, biasadj=FALSE, ...)

level is confidence level for prediction intervals.


Solution

  • Prediction intervals are useful because in forecasting you usually want to know the uncertainty of a future observation.

    I can't think why you would ever need a confidence interval for a future mean, but here is an example showing how you could compute it:

    library(forecast)
    fit <- auto.arima(WWWusage)
    fc <- forecast(fit, h=20, level=95)
    sim <- matrix(NA, ncol=20,nrow=1000)
    for(i in 1:1000)
      sim[i,] <- simulate(fit,20)
    se <- apply(sim,2,sd)/sqrt(1000)
    fc$upper <- fc$mean + 1.96*se
    fc$lower <- fc$mean - 1.96*se
    plot(fc)
    

    enter image description here