plot_irfs: Plot impulse response functions

View source: R/z_utils.R

plot_irfsR Documentation

Plot impulse response functions

Description

plot_irfs plots impulse response functions for a given array containing the impulse responses and possibly also error bands. This function returns a list of figures containing IRFs per variable.

Usage

plot_irfs(irf_arr, var_names, plot_title = "", label_y = TRUE)

Arguments

irf_arr

Matrix or array of dimension h+1 x q (w/o error bands) or (h+1 x 3 x q) (w/ error bands), where h is the number of periods in IRF and q is the number of variables of interest

var_names

Vector of variable names of the q impacted variables

plot_title

Title of the figure

label_y

Should the variable name be printed next to y-axis?

Value

list containing the figures

Examples

# Create a random IRF array: in case a matrix, rows denote the
# periods ahead while the columns are the reactions of the variables
h <- 24 # IRF horizon
q <- 4 # number of variables
irf_ex <- matrix(stats::rnorm((h+1)*q), h+1, q)
irf_ex <- apply(irf_ex, 2, cumsum)
p1 <- plot_irfs(irf_arr = irf_ex, var_names = letters[1:q])
# in case the supplied IRF element is array, the interpretation is as follows
# 1st dimension: length of the IRF horizon, 2nd dimension contain the
# lower error band, point estimate and upper error band estimates,
# 3rd is the of variables
irf_arr <- c(irf_ex-sd(irf_ex)*1.645, irf_ex, irf_ex+sd(irf_ex)*1.645) %>%
  array(dim= c(h+1, q, 3)) %>%
  aperm(c(1,3,2))
p2 <- plot_irfs(irf_arr, var_names = letters[1:4], label_y = FALSE)
## Not run: 
gridExtra::marrangeGrob(c(p1,p2), nrow = 4, ncol = 2)
## End(Not run)

juhokalle/rmfd4dfm documentation built on July 18, 2024, 10:19 p.m.