Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

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 1" title="Rendered by QuickLaTeX.com" height="13" width="47" style="vertical-align: -1px;"/>, if an ARIMA(p,d,q)(P,D,Q)_{12} is appropriate for the 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 is appropriate for 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)

Related

To leave a comment for the author, please follow the link and comment on their blog: Hyndsight » R.