Over a million developers have joined DZone.

Forecasting Annual Totals From Monthly Data

DZone's Guide to

Forecasting Annual Totals From Monthly Data

· Big Data Zone ·
Free Resource

The Architect’s Guide to Big Data Application Performance. Get the Guide.

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.

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)

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)

Learn how taking a DataOps approach will help you speed up processes and increase data quality by providing streamlined analytics pipelines via automation and testing. Learn More.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

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

{{ parent.tldr }}

{{ parent.urlSource.name }}