R/combinef.R
combinef.Rd
Using the methods of Hyndman et al. (2016) and 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.
combinef( fcasts, nodes = NULL, groups = NULL, weights = NULL, nonnegative = FALSE, algorithms = c("lu", "cg", "chol", "recursive", "slm"), keep = c("gts", "all", "bottom"), parallel = FALSE, num.cores = 2, control.nn = list() )
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. |
---|---|
nodes | If the object class is |
groups | If the object class is |
weights | A numeric vector. The default is |
nonnegative | Logical. Should the reconciled forecasts be non-negative? |
algorithms | An algorithm to be used for computing reconciled
forecasts. See |
keep | Return a |
parallel | Logical. Import parallel package to allow parallel processing. |
num.cores | Numeric. Specify how many cores are going to be used. |
control.nn | A list of control parameters to be passed on to the block principal pivoting algorithm. See 'Details'. |
Return the (non-negative) reconciled gts
object or forecasts at the bottom
level.
The control.nn
argument is a list that can supply any of the following components:
ptype
Permutation method to be used: "fixed"
or "random"
. Defaults to "fixed"
.
par
The number of full exchange rules that may be tried. Defaults to 10.
gtol
The tolerance of the convergence criteria. Defaults to sqrt(.Machine$double.eps)
.
Hyndman, R. J., Ahmed, R. A., Athanasopoulos, G., & Shang, H. L. (2011). Optimal combination forecasts for hierarchical time series. Computational Statistics and Data Analysis, 55(9), 2579--2589. https://robjhyndman.com/publications/hierarchical/
Hyndman, R. J., Lee, A., & Wang, E. (2016). Fast computation of reconciled forecasts for hierarchical and grouped time series. Computational Statistics and Data Analysis, 97, 16--32. https://robjhyndman.com/publications/hgts/
Wickramasuriya, S. L., Turlach, B. A., & Hyndman, R. J. (to appear). Optimal non-negative forecast reconciliation. Statistics and Computing. https://robjhyndman.com/publications/nnmint/
Alan Lee, Rob J Hyndman, Earo Wang and Shanika L Wickramasuriya
# hts example if (FALSE) { h <- 12 ally <- aggts(htseg1) 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, get_nodes(htseg1), weights = NULL, keep = "gts", algorithms = "lu") plot(y.f) } if (FALSE) { h <- 12 ally <- abs(aggts(htseg2)) allf <- matrix(NA, nrow = h, ncol = ncol(ally)) for(i in 1:ncol(ally)) allf[,i] <- forecast(auto.arima(ally[,i], lambda = 0, biasadj = TRUE), h = h)$mean b.f <- combinef(allf, get_nodes(htseg2), weights = NULL, keep = "bottom", algorithms = "lu") b.nnf <- combinef(allf, get_nodes(htseg2), weights = NULL, keep = "bottom", algorithms = "lu", nonnegative = TRUE) } # gts example if (FALSE) { abc <- ts(5 + matrix(sort(rnorm(200)), ncol = 4, nrow = 50)) g <- rbind(c(1,1,2,2), c(1,2,1,2)) y <- gts(abc, groups = g) h <- 12 ally <- aggts(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, groups = get_groups(y), keep ="gts", algorithms = "lu") plot(y.f) }