Learn R Programming

hts (version 3.03)

combinef: Optimally combine forecasts from a hierarchical time series

Description

Using the method of Hyndman et al. (2011), this function optimally combines the forecasts at all levels of a hierarchical time series. The forecast.gts calls this function when the comb method is selected.

Usage

combinef(fcasts, S, return=c("gts","matrix","bottomlevelonly"), hierarchical=FALSE)

Arguments

fcasts
Matrix of forecasts for all levels of the hierarchical time series. Each row represents one forecast horizon and each column represents one time series from the hierarchy.
S
The summing matrix defining how the forecasts at the bottom level are summed to obtain each time series in the hierarchy.
return
determines what type and class of object to return.
hierarchical
indicates if the grouped time series should be hierarchical. Ignored if return!="gts".

Value

  • Either an object of class gts or a matrix of forecasts. If a matrix is returned, it can be the same size as fcasts (if return=="matrix") or just the bottom-level forecasts (if return=="bottomlevelonly").

References

R. J. Hyndman, R. A. Ahmed, G. Athanasopoulos and H.L. Shang (2011) Optimal combination forecasts for hierarchical time series. Computational Statistics and Data Analysis, 55(9), 2579--2589. http://robjhyndman.com/papers/hierarchical/

See Also

hts, forecast.gts

Examples

Run this code
# Construct data
abc <- ts(5 + matrix(sort(rnorm(200)), ncol = 4, nrow = 50))
y <- gts(abc, rbind(c(1,1,2,2), c(1,2,1,2)))
h <- 12 
ally <- allts(y)
allf <- matrix(NA,nrow=h,ncol=ncol(ally))
for(i in 1:ncol(ally))
	allf[,i] <- forecast(auto.arima(ally[,i]),h=h)$mean
allf <- ts(allf, start=51)
y.f <- combinef(allf,Smatrix(y), return="gts")
plot(y.f)

Run the code above in your browser using DataLab