gfevd: Generalised Forecast Error Variance Decomposition

View source: R/gfevd.R

gfevdR Documentation

Generalised Forecast Error Variance Decomposition

Description

Produces the generalised forecast error variance decomposition of a Bayesian GVAR model.

A plot function for objects of class "bgvarfevd".

Usage

gfevd(object, response, n.ahead = 5, normalise_gir = FALSE, mc.cores = NULL)

## S3 method for class 'bgvarfevd'
plot(x, top_n = 5L, group = "variable", ...)

Arguments

object

an object of class "bgvar", usually, a result of a call to combine_submodels.

response

a character vector of the response country and variable, respectively.

n.ahead

number of steps ahead.

normalise_gir

logical. Should the GFEVD be normalised?

mc.cores

the number of cores to use, i.e. at most how many child processes will be run simultaneously. The option is initialized from environment variable MC_CORES if set. Must be at least one, and parallelization requires at least two cores.

x

an object of class "bgvarfevd", usually, a result of a call to gfevd.

top_n

integer specifying the amount of the most explaining variables that should be displayed

group

either "variable" (default) for variable-wise or "country" for country-wise decompositions.

...

further graphical parameters.

Details

For the global VAR model

y_t = \sum_{l = 1}^{p} G_l y_{t - j} + G^{-1}_{0} u_t

with u_t \sim \Sigma and G_i as K \times K coefficient matrices the function produces the generalised structural forecast error variance decomposition as

\omega^{GIR}_{jk, h} = \frac{\sigma^{-1}_{jj} \sum_{i = 0}^{h-1} (e_j^{\prime} \Phi_i G_0^{-1} \Sigma e_k )^2}{\sum_{i = 0}^{h-1} (e_j^{\prime} \Phi_i G_0^{-1} \Sigma G_0^{-1 \prime} \Phi_i^{\prime} e_j )},

where \Phi_i is the forecast error impulse response for the ith period, \Sigma is the variance-covariance matrix of the error term, e_j is a selection vector for the response variable, e_k is a selection vector for the impulse variable, and \sigma_{jj} is the diagonal element of the jth variable of the variance covariance matrix.

Since GIR-based FEVDs do not add up to unity, they can be normalised by setting normalise_gir = TRUE.

Value

A time-series object of class "bgvarfevd".

References

Lütkepohl, H. (2007). New introduction to multiple time series analysis (2nd ed.). Berlin: Springer.

Pesaran, H. H., & Shin, Y. (1998). Generalized impulse response analysis in linear multivariate models. Economics Letters, 58, 17-29.

Examples

# Load data
data("gvar2019")

# Create regions
temp <- create_regions(country_data = gvar2019$country_data,
             weight_data = gvar2019$weight_data,
             region_weights = gvar2019$region_weights,
             regions = list(EA =  c("AT", "BE", "DE", "ES", "FI", "FR", "IT", "NL")),
             period = 3)

country_data <- temp$country_data
weight_data <- temp$weight_data
global_data = gvar2019$global_data

# Difference series to make them stationary
country_data <- diff_variables(country_data, variables = c("y", "Dp", "r"), multi = 100)
global_data <- diff_variables(global_data, multi = 100)

# Create time varying weights
weight_data <- create_weights(weight_data, period = 3, country_data = country_data)

# Generate specifications
model_specs <- create_specifications(
                 country_data = country_data,
                 global_data = global_data,
                 countries = c("US", "JP", "CA", "NO", "GB", "EA"), 
                 domestic = list(variables = c("y", "Dp", "r"), lags = 1),
                 foreign = list(variables = c("y", "Dp", "r"), lags = 1),
                 global = list(variables = c("poil"), lags = 1),
                 deterministic = list(const = TRUE, trend = FALSE, seasonal = FALSE),
                 iterations = 10,
                 burnin = 10)
# Note that the number of iterations and burnin draws should be much higher!
                                     
# Overwrite country-specific specifications
model_specs[["US"]][["domestic"]][["variables"]] <- c("y", "Dp", "r")
model_specs[["US"]][["foreign"]][["variables"]] <- c("y", "Dp")

# Create estimation objects
country_models <- create_models(country_data = country_data,
                                weight_data = weight_data,
                                global_data = global_data,
                                model_specs = model_specs)

# Add priors
models_with_priors <- add_priors(country_models,
                                 coef = list(v_i = 1 / 9, v_i_det = 1 / 10),
                                 sigma = list(df = 3, scale = .0001))

# Obtain posterior draws
object <- draw_posterior(models_with_priors)

# Solve GVAR
gvar <- combine_submodels(object)

# Obtain forecasts
gvar_fevd <- gfevd(gvar, response = c("US", "y"))

# Plot forecast
plot(gvar_fevd) 


franzmohr/bgvars documentation built on Sept. 2, 2023, 12:45 p.m.