irf.bvar {BVAR}R Documentation

Impulse response and forecast error methods for Bayesian VARs


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 the results you may want to assign the output using the setter function (irf(x) <- irf(x)). May also be used to update confidence bands.


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

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

irf(x, ...)

irf(x) <- value

fevd(x, ...)

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


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.


Numeric vector of 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.


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


A bvar_irf object to assign.

vars_impulse, vars_response

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


Returns a list of class bvar_irf including IRFs and optionally FEVDs at desired confidence bands. The fevd method only returns a the nested bvar_fevd object. The summary method returns a numeric array of impulse responses at the specified confidence bands.

See Also

plot.bvar_irf; bv_irf


# Access a subset of the fred_qd dataset
data <- fred_qd[, c("CPIAUCSL", "UNRATE", "FEDFUNDS")]
# Transform it to be stationary
data <- fred_transform(data, codes = c(5, 5, 1), lag = 4)

# Estimate a BVAR using one lag, default settings and very few draws
x <- bvar(data, lags = 1, n_draw = 1000L, n_burn = 200L, verbose = FALSE)

# Calculate and store structural IRFs (via Cholesky decomposition)
irf(x) <- irf(x, identification = TRUE)

# Update the confidence bands of the IRFs
irf(x, conf_bands = c(0.01, 0.05, 0.1))

# Compute and store with a longer horizon, no identification and thinning
irf(x) <- irf(x, bv_irf(horizon = 24L, identification = FALSE), n_thin = 10L)

# Recalculate with sign restrictions provided via the ellipsis
irf(x, sign_restr = matrix(c(1, NA, NA, -1, 1, -1, -1, 1, 1), nrow = 3))

# Recalculate with zero and sign restrictions provided via the ellipsis
irf(x, sign_restr = matrix(c(1, 0, 1, NA, 1, 1, -1, -1, 1), nrow = 3))

# Calculate the forecast error variance decomposition

# Get a summary of the saved impulse response function

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

[Package BVAR version 1.0.1 Index]