Solved – How to add confidence intervals to cumulated timeseries

arimaconfidence intervaltime series

I'm forecasting a timeseries with arima, and want to plot the cumulated predictions. How can i add the according confidence intervals? I'ts my understanding that I can't simply cumulate the intervals as well, right? But how can I add them?

library(forecast)
library(ggplot2)
library(dplyr)

AirPassengers

model <- Arima(AirPassengers)

model <- auto.arima(AirPassengers)


prediction <- forecast(model, h = 12)

prediction_df <- data.frame(time = 1:12,
  point = prediction$mean %>% as.numeric,
                            lo_95 = prediction$lower[,2] %>% as.numeric,
                            hi_95 = prediction$upper[,2] %>% as.numeric)



ggplot(prediction_df, aes(x = time, y = point)) +
  geom_line() +
  ylim(0, 700) +
  geom_ribbon(aes(ymin = lo_95, ymax = hi_95), alpha = 0.2, fill = "blue")



prediction_cum <- data.frame(time = 1:12,
                             point = cumsum(prediction$mean),
                             lo_95 = cumsum(prediction$lower[, 2]),
                             hi_95 = cumsum(prediction$upper[, 2])
                                            )


ggplot(prediction_cum, aes(x = time, y = point)) +
  geom_line() +
  geom_point() +
  geom_ribbon(aes(ymin = lo_95, ymax = hi_95), alpha = 0.2, fill = "blue")

Best Answer

One approach which I have incorporated into AUTOBOX ( a piece of software that I have helped to develop) is to generate via monte carlo predictions via bootstrapping. The predictions are based upon the model errors and the possible changing forecast variance. These forecasts are saved to the operating system and available for recall. For example one can then take the family of forecasts for 1 period out and for 2 periods out and randomly aggregate them to create a family of forecasts for the sum of the first two periods out etc.

This feature is also available to causal models thus uncertainties in the forecast are based upon the distribution of uncertainties in each of the predictors. Another interesting feature is the introduction of incorporating uncertainties due to pulses (one time anomalies) providing more realistic prediction intervals.

Hope this helps you and others ....

Related Question