Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
This question was posed on crossvalidated.com:
I have a monthly time series (for 2009–2012 non-stationary, with seasonality). I can use ARIMA (or ETS) to obtain point and interval forecasts for each month of 2013, but I am interested in forecasting the total for the whole year, including prediction intervals. Is there an easy way in R to obtain interval forecasts for the total for 2013?
I’ve come across this problem before in my consulting work, although I don’t think I’ve ever published my solution. So here it is.
If x
is your monthly time series, then you can construct annual totals as follows.
library(forecast) y <- filter(x,rep(1,12), sides=1) # Total of last 12 months |
To get the forecasts of the annual totals:
fit <- auto.arima(y) forecast(fit,h=12) |
The last forecast is for the total of the next year.
Note that diff(y,lag=1)
is the same as diff(x,lag=12)
. So, provided x
series, then an ARIMA(p,d+1,q)(P,D-1,Q)12 is appropriate for the y
series. However, auto.arima
may not choose the equivalent models because the filtering and differencing will lead to different numbers of observations. To take advantage of this result, and use all the available data as efficiently as possible, the following code is better, assuming x
:
fit <- auto.arima(x,d=1,D=1) fit$arma[c(6,7)] <- c(2,0) fit <- Arima(y,model=fit) forecast(fit,h=12) |
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.