Fitted Confidence Intervals Forecast Function R

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,

1 Answer

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:

library(forecast)
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)
lines(Nile)
lines(fitted(fit),col='red')
out <- (Nile < lower | Nile > upper)
points(time(Nile)[out], Nile[out], pch=19)


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