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)
A <- rec_mat$A
# Set the parameters of the Poisson base forecast distributions
lambda1 <- 2
lambda2 <- 4
lambdaY <- 9
lambdas <- c(lambdaY, lambda1, lambda2)
base_fc <- list()
for (i in 1:length(lambdas)) {
base_fc[[i]] <- list(lambda = lambdas[i])
}
# Sample from the reconciled forecast distribution using MCMC
mcmc <- reconc_MCMC(A, base_fc,
distr = "poisson",
num_samples = 30000, seed = 42
)
samples_mcmc <- rbind(mcmc$upper_rec_samples, mcmc$bottom_rec_samples)
# Compare the reconciled means with those obtained via BUIS
buis <- reconc_BUIS(A, base_fc,
in_type = "params",
distr = "poisson", num_samples = 100000, seed = 42
)
samples_buis <- rbind(buis$upper_rec_samples, buis$bottom_rec_samples)
print(rowMeans(samples_mcmc))
print(rowMeans(samples_buis))
Run the code above in your browser using DataLab