Title: | Tidy Bayesian Vector Autoregression |
---|---|
Description: | Functions to prepare tidy objects from estimated models via 'BVAR' (see Kuschnig & Vashold, 2019 <doi:10.13140/RG.2.2.25541.60643>) and visualisation thereof. Bridges the gap between estimating models with 'BVAR' and plotting the results in a more sophisticated way with 'ggplot2' as well as passing them on in a tidy format. |
Authors: | Lukas Vashold [aut, cre] , Nikolas Kuschnig [aut] |
Maintainer: | Lukas Vashold <[email protected]> |
License: | GPL-3 |
Version: | 0.0.1 |
Built: | 2024-11-04 03:02:54 UTC |
Source: | https://github.com/nk027/bvarverse |
Turn the outputs of a Bayesian VAR (see bvar
) into a
an augmented tibble. Methods are available for bvar
objects (will
yield coefficients and their quantiles), bvar_fcast
objects (with
predictions, their quantiles and optionally real datapoints), and
bvar_irf
objects (with impulse responses).
## S3 method for class 'bvar' augment(x, conf_bands = 0.16, ...) ## S3 method for class 'bvar_fcast' augment(x, t_back = 0L, ...) ## S3 method for class 'bvar_irf' augment(x, ...)
## S3 method for class 'bvar' augment(x, conf_bands = 0.16, ...) ## S3 method for class 'bvar_fcast' augment(x, t_back = 0L, ...) ## S3 method for class 'bvar_irf' augment(x, ...)
x |
A |
conf_bands |
Numeric vector. Credible intervals of coefficients to include in the tibble. |
... |
Not used. |
t_back |
Integer scalar. Whether to include actual datapoints in the tidied forecast. |
Returns a tibble
with relevant information;
quantiles can be found in the columns.
# 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) # Create tibbles from the outputs augment(x) augment(irf(x)) augment(predict(x))
# 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) # Create tibbles from the outputs augment(x) augment(irf(x)) augment(predict(x))
Function to quickly plot outputs from bvar
and derived objects.
Supported plots include traces and densities, forecasts, and impulse
response functions. For more flexible plots one may use the outputs of
tidy.bvar
and augment.bvar
.
bv_ggplot(x, ...) ## Default S3 method: bv_ggplot(x, ...) ## S3 method for class 'bvar_chains' bv_ggplot(x, ...) ## S3 method for class 'bvar' bv_ggplot( x, type = c("trace", "density"), vars = NULL, vars_response = NULL, vars_impulse = NULL, orientation = c("horizontal", "vertical"), chains = list(), ... ) ## S3 method for class 'bvar_irf' bv_ggplot(x, vars_response = NULL, vars_impulse = NULL, col = "#737373", ...) ## S3 method for class 'bvar_fcast' bv_ggplot(x, vars = NULL, col = "#737373", t_back = 1L, ...)
bv_ggplot(x, ...) ## Default S3 method: bv_ggplot(x, ...) ## S3 method for class 'bvar_chains' bv_ggplot(x, ...) ## S3 method for class 'bvar' bv_ggplot( x, type = c("trace", "density"), vars = NULL, vars_response = NULL, vars_impulse = NULL, orientation = c("horizontal", "vertical"), chains = list(), ... ) ## S3 method for class 'bvar_irf' bv_ggplot(x, vars_response = NULL, vars_impulse = NULL, col = "#737373", ...) ## S3 method for class 'bvar_fcast' bv_ggplot(x, vars = NULL, col = "#737373", t_back = 1L, ...)
x |
A |
... |
Not used. |
type |
A string with the type (trace or density) of plot desired. |
vars |
Character vector used to select variables. Elements are matched
to hyperparameters or coefficients. Coefficients may be matched based on
the dependent variable (by providing the name or position) or the
explanatory variables (by providing the name and the desired lag). See the
example section for a demonstration. Defaults to |
vars_response |
Optional character or integer vectors used
to select coefficents. Dependent variables are specified with
vars_response, explanatory ones with vars_impulse. Defaults to
|
vars_impulse |
Optional character or integer vectors used
to select coefficents. Dependent variables are specified with
vars_response, explanatory ones with vars_impulse. Defaults to
|
orientation |
A string indicating the desired orientation of trace or density plots |
chains |
List of |
col |
Character vector. Colour(s) of the lines delineating credible
intervals. Single values will be recycled if necessary. Recycled HEX color
codes are varied in transparency if not provided (e.g. "#737373FF"). Lines
can be bypassed by setting this to |
t_back |
Integer scalar. Whether to include actual datapoints in the tidied forecast. |
Returns a ggplot
object with a basic structure.
# 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) # Plot the outputs - alternatively use ggplot() with fortify() bv_ggplot(x) bv_ggplot(irf(x)) bv_ggplot(predict(x))
# 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) # Plot the outputs - alternatively use ggplot() with fortify() bv_ggplot(x) bv_ggplot(irf(x)) bv_ggplot(predict(x))
Turn the outputs of a Bayesian VAR (see bvar
) into a
a tidy tibble. Methods are available for bvar
objects (will yield a
subset of coefficient and/or hyperparameter draws), bvar_coefs
objects
(with the coefficients and their quantiles) bvar_fcast
objects (with
predictions, their quantiles and optionally real datapoints), and
bvar_irf
objects (with impulse responses).
## S3 method for class 'bvar' tidy( x, vars = NULL, vars_response = NULL, vars_impulse = NULL, chains = list(), ... ) ## S3 method for class 'bvar_coefs' tidy(x, ...) ## S3 method for class 'bvar_fcast' tidy(x, t_back = 0L, ...) ## S3 method for class 'bvar_irf' tidy(x, ...)
## S3 method for class 'bvar' tidy( x, vars = NULL, vars_response = NULL, vars_impulse = NULL, chains = list(), ... ) ## S3 method for class 'bvar_coefs' tidy(x, ...) ## S3 method for class 'bvar_fcast' tidy(x, t_back = 0L, ...) ## S3 method for class 'bvar_irf' tidy(x, ...)
x |
A |
vars |
Character vector used to select variables. Elements are matched
to hyperparameters or coefficients. Coefficients may be matched based on
the dependent variable (by providing the name or position) or the
explanatory variables (by providing the name and the desired lag). See the
example section for a demonstration. Defaults to |
vars_impulse , vars_response
|
Optional character or integer vectors used
to select coefficents. Dependent variables are specified with
vars_response, explanatory ones with vars_impulse. Defaults to
|
chains |
List of |
... |
Not used. |
t_back |
Integer scalar. Whether to include actual datapoints in the tidied forecast. |
Returns a tidy tibble
with relevant
information for further processing.
# 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) # Create tidy tibbles from the outputs tidy(x) tidy(irf(x)) tidy(predict(x))
# 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) # Create tidy tibbles from the outputs tidy(x) tidy(irf(x)) tidy(predict(x))