| KL | R Documentation |
KL function APR suggest this measure to assess the "plausibility" of the conditional forecast. It is based on the Kullback-Leibler measure of distance between the unconditional forecast and the conditional/scenario forecast.
KL(Sigma_eps, mu_eps, h, plot_ = FALSE, max_cores = NULL)
Sigma_eps |
variance of innovation |
mu_eps |
mean of innovation |
h |
forecast horizon |
plot_ |
logical; if TRUE then a histogram of the KL measure is returned |
max_cores |
maximum number of cores to use for parallel processing (default: NULL, uses CRAN-compliant detection with Windows=1) |
Returns the APR 'q': ie distance from a fair binomial distribution
# Example with simulated innovation data
# Set dimensions
n_var <- 3
h <- 4
n_draws <- 10
n_innovations <- n_var * h
# Create simulated innovation means and covariances
set.seed(123)
mu_eps <- array(rnorm(n_innovations * 1 * n_draws, mean = 0, sd = 0.1),
dim = c(n_innovations, 1, n_draws))
Sigma_eps <- array(0, dim = c(n_innovations, n_innovations, n_draws))
for (d in 1:n_draws) {
temp_cov <- matrix(rnorm(n_innovations^2), n_innovations, n_innovations)
Sigma_eps[,,d] <- temp_cov %*% t(temp_cov) + diag(n_innovations) * 0.5
}
# Calculate KL measure
kl_result <- KL(Sigma_eps, mu_eps, h, plot_ = FALSE)
print(head(kl_result[[1]])) # Print first few q values
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.