Learn R Programming

BVAR (version 0.2.0)

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 them to x[["irf"]]. May also be used to update confidence bands.

Usage

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

# S3 method for bvar_irf irf(x, conf_bands, ...)

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

# S3 method for bvar_irf fevd(x, conf_bands = 0.5, ...)

irf(x, ...)

fevd(x, ...)

# S3 method for bv_irf print(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, ...)

# S3 method for bvar_irf_summary print(x, digits = 2L, ...)

Arguments

x, object

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

...

A bv_fcast object or parameters to be fed into bv_fcast. Contains settings for the forecast.

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. Defaults to the maximum number - i.e. the number of saved draws in x.

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, optionally FEVDs, and desired confidence bands. See bvar. The fevd methods only returns a numeric array of FEVDs and desired confidence bands. The summary method returns a numeric array of forecast paths 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