I am using the forecast function in R written by Rob Hyndman. I am trying to determine the best way to determine confidence intervals for the historical fitted values. I would like to plot how often the historical forecast exceeded the 95% confidence interval at that time.

Thank you in advance,


Presumably you mean prediction intervals rather than confidence intervals.

The fitted values are in-sample one-step forecasts. Assuming normally distributed errors, 95% prediction intervals are given by $$\hat{y}_t \pm 1.96 \hat{\sigma}$$ where $\hat\sigma^2$ is the estimated variance of the residuals.

Here is an example using R:

fit <- auto.arima(Nile)
upper <- fitted(fit) + 1.96*sqrt(fit$sigma2)
lower <- fitted(fit) - 1.96*sqrt(fit$sigma2)
plot(Nile, type="n", ylim=range(lower,upper))
polygon(c(time(Nile),rev(time(Nile))), c(upper,rev(lower)), 
   col=rgb(0,0,0.6,0.2), border=FALSE)
out <- (Nile < lower | Nile > upper)
points(time(Nile)[out], Nile[out], pch=19)

  • 2
    $\begingroup$ Thank you Rob! All of your work with this package and the online tutorials is much appreciated! $\endgroup$ – Daniel May 29 '15 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.