predict.bgvar: Plotting Forecasts of BVAR Models

View source: R/predict.bgvar.R

plot.bgvarprdR Documentation

Plotting Forecasts of BVAR Models

Description

A plot function for objects of class "bvarprd".

Forecasting a Bayesian Global VAR object of class "bgvar" with credible bands.

Usage

## S3 method for class 'bgvarprd'
plot(x, variable = NULL, ...)

## S3 method for class 'bgvar'
predict(object, ..., n.ahead = 10, new_x = NULL, new_d = NULL, ci = 0.95)

Arguments

x

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

variable

a character vector containing a country name as its first and a variable name as its second element. If NULL (default) all series are plotted.

...

additional arguments.

object

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

n.ahead

number of steps ahead at which to predict.

new_x

a matrix of new non-deterministic, exogenous variables. Must have n.ahead rows.

new_d

a matrix of new deterministic variables. Must have n.ahead rows.

ci

a numeric between 0 and 1 specifying the probability mass covered by the credible intervals. Defaults to 0.95.

Details

The function produces n.ahead forecasts for the GVAR model

y_t = \sum_{l = 1}^{p} G_{l} y_{t-i} + \sum_{l = 0}^{s} H_{l} x_{t-i} + D d_t + G^{-1}_{0} u_t,

with u_t \sim N(0, \Sigma).

Value

A time-series object of class "bgvarprd".

References

Lütkepohl, H. (2007). New introduction to multiple time series analyis. Berlin: Springer.

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 = 2),
                 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_prd <- predict(gvar)

# Plot forecast
plot(gvar_prd, variable = c("US", "y")) 



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