Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Forecasting Annual Totals From Monthly Data

DZone's Guide to

Forecasting Annual Totals From Monthly Data

· Big Data Zone
Free Resource

Learn how you can maximize big data in the cloud with Apache Hadoop. Download this eBook now. Brought to you in partnership with Hortonworks.

This ques­tion was posed on cross​val​i​dated​.com:

I have a monthly time series (for 2009–2012 non-​​stationary, with sea­son­al­ity). I can use ARIMA (or ETS) to obtain point and inter­val fore­casts for each month of 2013, but I am inter­ested in fore­cast­ing the total for the whole year, includ­ing pre­dic­tion inter­vals. Is there an easy way in R to obtain inter­val fore­casts for the total for 2013?

I’ve come across this prob­lem before in my con­sult­ing work, although I don’t think I’ve ever pub­lished my solu­tion. So here it is.

If x is your monthly time series, then you can con­struct annual totals as follows.

library(forecast)
y <- filter(x,rep(1,12), sides=1) # Total of last 12 months

To get the fore­casts of the annual totals:

fit <- auto.arima(y)
forecast(fit,h=12)

The last fore­cast is for the total of the next year.

Note that diff(y,lag=1) is the same as diff(x,lag=12). So, pro­vided D>1, if anARIMA(p,d,q)(P,D,Q)12 is appro­pri­ate for the x series, then an ARIMA(p,d+1,q)(P,D-1,Q)12 is appro­pri­ate for the y series. How­ever, auto.arima may not choose the equiv­a­lent mod­els because the fil­ter­ing and dif­fer­enc­ing will lead to dif­fer­ent num­bers of obser­va­tions. To take advan­tage of this result, and use all the avail­able data as effi­ciently as pos­si­ble, the fol­low­ing code is bet­ter, assum­ing d=D=1 is appro­pri­ate 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)

Hortonworks DataFlow is an integrated platform that makes data ingestion fast, easy, and secure. Download the white paper now.  Brought to you in partnership with Hortonworks

Topics:

Published at DZone with permission of Rob J Hyndman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}