Learn R Programming

BVAR (version 0.2.2)

irf.bvar: Impulse response and forecast error methods for Bayesian VARs

Description

Retrieves / calculates impulse response functions (IRFs) and/or forecast error variance decompositions (FEVDs) for Bayesian VARs generated via bvar. If the object is already present and no settings are supplied it is simply retrieved, otherwise it will be calculated ex-post. Note that FEVDs require the presence / calculation of IRFs. To store IRFs you may want to assign the output of irf.bvar to x$irf. May also be used to update confidence bands, i.e. credible intervals.

Usage

# S3 method for bvar
irf(x, ..., conf_bands, n_thin = 1L)

# S3 method for bvar fevd(x, ..., conf_bands = 0.5, n_thin = 1L)

irf(x, ...)

fevd(x, ...)

# S3 method for bvar_irf print(x, ...)

# S3 method for bvar_fevd print(x, digits = 4L, complete = FALSE, ...)

# S3 method for bvar_irf summary(object, vars_impulse = NULL, vars_response = NULL, ...)

Arguments

x, object

A bvar object, obtained from bvar. Summary and print methods take in a bvar_irf / bvar_fevd object.

...

A bv_irf object or arguments to be fed into bv_irf. Contains settings for the IRFs / FEVDs.

conf_bands

Numeric vector of desired confidence bands to apply. E.g. for bands at 5%, 10%, 90% and 95% set this to c(0.05, 0.1). Note that the median, i.e. 0.5 is always included.

n_thin

Integer scalar. Every n_thin'th draw in x is used for calculations, others are dropped.

digits

Integer scalar. Fed to round and applied to numeric outputs (i.e. the quantiles).

complete

Logical scalar. Whether to print only medians or all available confidence bands of a a bvar_fevd object.

vars_impulse, vars_response

Optional numeric or character vector. Used to subset the summary's impulses / responses to certain variables by position or name (must be available). Defaults to NULL, i.e. all variables.

Value

Returns a list of class bvar_irf including IRFs and optionally FEVDs at desired confidence bands. Also see bvar. Note that the fevd method only returns a numeric array of FEVDs at desired confidence bands. The summary method returns a numeric array of impulse responses at the specified confidence bands.

See Also

bvar; plot.bvar_irf; bv_irf

Examples

Run this code
# NOT RUN {
data <- matrix(rnorm(400), ncol = 4)
x <- bvar(data, lags = 2)

# Add IRFs
x$irf <- irf(x)

# Access IRFs and update confidence bands
irf(x, conf_bands = 0.01)

# Compute and store IRFs with a longer horizon
x$irf <- irf(x, horizon = 24L)

# Lower draws, use `bv_irf()` to set options and add confidence bands
irf(x, bv_irf(24L), n_thin = 10L, conf_bands = c(0.05, 0.16))

# Get a summary of the last saved IRFs
summary(x)

# Limit the summary to responses of variable #2
summary(x, vars_response = 2L)
# }

Run the code above in your browser using DataLab