reconc_BUIS {bayesRecon}R Documentation

BUIS for Probabilistic Reconciliation of forecasts via conditioning

Description

Uses the Bottom-Up Importance Sampling algorithm to draw samples from the reconciled forecast distribution, which is obtained via conditioning.

Usage

reconc_BUIS(
  S,
  base_forecasts,
  in_type,
  distr,
  num_samples = 20000,
  suppress_warnings = FALSE,
  seed = NULL
)

Arguments

S

Summing matrix (n x n_bottom).

base_forecasts

A list containing the base_forecasts, see details.

in_type

A string or a list of length n. If it is a list the i-th element is a string with two possible values:

  • 'samples' if the i-th base forecasts are in the form of samples;

  • 'params' if the i-th base forecasts are in the form of estimated parameters.

If it in_type is a string it is assumed that all base forecasts are of the same type.

distr

A string or a list of length n describing the type of base forecasts. If it is a list the i-th element is a string with two possible values:

  • 'continuous' or 'discrete' if in_type[[i]]='samples';

  • 'gaussian', 'poisson' or 'nbinom' if in_type[[i]]='params'.

If distr is a string it is assumed that all distributions are of the same type.

num_samples

Number of samples drawn from the reconciled distribution.

suppress_warnings

Logical. If TRUE, no warnings about effective sample size are triggered. If FALSE, warnings are generated. Default is FALSE. See Details.

seed

Seed for reproducibility.

Details

The parameter base_forecast is a list containing n elements where the i-th element depends on the values of in_type[[i]] and distr[[i]].

If in_type[[i]]='samples', then base_forecast[[i]] is a vector containing samples from the base forecast distribution.

If in_type[[i]]='params', then base_forecast[[i]] is a vector containing the estimated:

See the description of the parameters in_type and distr for more details.

The order of the base_forecast list is given by the order of the time series in the summing matrix.

Warnings are triggered from the Importance Sampling step if:

Note that warnings are an indication that the base forecasts might have issues. Please check the base forecasts in case of warnings.

Value

A list containing the reconciled forecasts. The list has the following named elements:

References

Zambon, L., Azzimonti, D. & Corani, G. (2024). Efficient probabilistic reconciliation of forecasts for real-valued and count time series. doi:10.1007/s11222-023-10343-y.

See Also

reconc_gaussian()

Examples


library(bayesRecon)

# Create a minimal hierarchy with 2 bottom and 1 upper variable
rec_mat <- get_reconc_matrices(agg_levels=c(1,2), h=2)
S <- rec_mat$S


#1) Gaussian base forecasts

#Set the parameters of the Gaussian base forecast distributions
mu1 <- 2
mu2 <- 4
muY <- 9
mus <- c(muY,mu1,mu2)

sigma1 <- 2
sigma2 <- 2
sigmaY <- 3
sigmas <- c(sigmaY,sigma1,sigma2)

base_forecasts = list()
for (i in 1:nrow(S)) {
base_forecasts[[i]] = c(mus[[i]], sigmas[[i]])
}


#Sample from the reconciled forecast distribution using the BUIS algorithm
buis <- reconc_BUIS(S, base_forecasts, in_type="params",
                 distr="gaussian", num_samples=100000, seed=42)

samples_buis <- buis$reconciled_samples

#In the Gaussian case, the reconciled distribution is still Gaussian and can be
#computed in closed form
Sigma <- diag(sigmas^2)  #transform into covariance matrix
analytic_rec <- reconc_gaussian(S, base_forecasts.mu = mus,
                                base_forecasts.Sigma = Sigma)

#Compare the reconciled means obtained analytically and via BUIS
print(c(S %*% analytic_rec$bottom_reconciled_mean))
print(rowMeans(samples_buis))


#2) Poisson base forecasts

#Set the parameters of the Poisson base forecast distributions
lambda1 <- 2
lambda2 <- 4
lambdaY <- 9
lambdas <- c(lambdaY,lambda1,lambda2)

base_forecasts <- list()
for (i in 1:nrow(S)) {
 base_forecasts[[i]] = lambdas[i]
}

#Sample from the reconciled forecast distribution using the BUIS algorithm
buis <- reconc_BUIS(S, base_forecasts, in_type="params",
                          distr="poisson", num_samples=100000, seed=42)
samples_buis <- buis$reconciled_samples

#Print the reconciled means
print(rowMeans(samples_buis))


[Package bayesRecon version 0.2.0 Index]