Learn R Programming

bayesRecon (version 0.2.0)

reconc_gaussian: Analytical reconciliation of Gaussian base forecasts

Description

Closed form computation of the reconciled forecasts in case of Gaussian base forecasts.

Usage

reconc_gaussian(S, base_forecasts.mu, base_forecasts.Sigma)

Value

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

  • bottom_reconciled_mean: reconciled mean for the bottom forecasts;

  • bottom_reconciled_covariance: reconciled covariance for the bottom forecasts.

Arguments

S

summing matrix (n x n_bottom).

base_forecasts.mu

a vector containing the means of the base forecasts.

base_forecasts.Sigma

a matrix containing the covariance matrix of the base forecasts.

Details

The order of the base forecast means and covariance is given by the order of the time series in the summing matrix.

The function returns only the reconciled parameters of the bottom variables. The reconciled upper parameters and the reconciled samples for the entire hierarchy can be obtained from the reconciled bottom parameters. See the example section.

References

Corani, G., Azzimonti, D., Augusto, J.P.S.C., Zaffalon, M. (2021). Probabilistic Reconciliation of Hierarchical Forecast via Bayes' Rule. In: Hutter, F., Kersting, K., Lijffijt, J., Valera, I. (eds) Machine Learning and Knowledge Discovery in Databases. ECML PKDD 2020. Lecture Notes in Computer Science(), vol 12459. Springer, Cham. tools:::Rd_expr_doi("10.1007/978-3-030-67664-3_13").

Zambon, L., Agosto, A., Giudici, P., Corani, G. (2023). Properties of the reconciled distributions for Gaussian and count forecasts. tools:::Rd_expr_doi("10.48550/arXiv.2303.15135").

See Also

reconc_BUIS()

Examples

Run this code

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
A <- rec_mat$A

#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)

Sigma <- diag(sigmas^2)  #need to transform into covariance matrix
analytic_rec <- reconc_gaussian(S, base_forecasts.mu = mus,
                               base_forecasts.Sigma = Sigma)

bottom_mu_reconc <- analytic_rec$bottom_reconciled_mean
bottom_Sigma_reconc <- analytic_rec$bottom_reconciled_covariance

# Obtain reconciled mu and Sigma for the upper variable
upper_mu_reconc <- A %*% bottom_mu_reconc
upper_Sigma_reconc <- A %*% bottom_Sigma_reconc %*% t(A)

# Obtain reconciled mu and Sigma for the entire hierarchy
Y_mu_reconc <- S %*% bottom_mu_reconc
Y_Sigma_reconc <- S %*% bottom_Sigma_reconc %*% t(S)  # note: singular matrix

# Obtain reconciled samples for the entire hierarchy:
# i.e., sample from the reconciled bottoms and multiply by S
chol_decomp = chol(bottom_Sigma_reconc) # Compute the Cholesky Decomposition
Z = matrix(rnorm(n = 2000), nrow = 2) # Sample from standard normal
B = chol_decomp %*% Z + matrix(rep(bottom_mu_reconc, 1000), nrow=2) # Apply the transformation

U = S %*% B
Y_reconc = rbind(U, B)

Run the code above in your browser using DataLab