density.bvar: Density methods for Bayesian VARs

View source: R/93_density.R

density.bvarR Documentation

Density methods for Bayesian VARs

Description

Calculates densities of hyperparameters or coefficient draws from Bayesian VAR models generated via bvar. Wraps standard density outputs into a list.

Usage

## S3 method for class 'bvar'
density(x, vars = NULL, vars_response = NULL, vars_impulse = NULL, ...)

## S3 method for class 'bvar_density'
plot(x, mar = c(2, 2, 2, 0.5), mfrow = c(length(x), 1), ...)

independent_index(var, n_vars, lag)

Arguments

x

A bvar object, obtained from bvar.

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 NULL, i.e. all hyperparameters.

vars_response, vars_impulse

Optional character or integer vectors used to select coefficents. Dependent variables are specified with vars_response, explanatory ones with vars_impulse. See the example section for a demonstration.

...

Fed to density or par.

mar

Numeric vector. Margins for par.

mfrow

Numeric vector. Rows for par.

var, n_vars, lag

Integer scalars. Retrieve the position of lag lag of variable var given n_vars total variables.

Value

Returns a list with outputs of density.

See Also

bvar; density

Examples


# 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)

# Get densities of the hyperparameters
density(x)

# Plot them
plot(density(x))

# Only get the densities associated with dependent variable 1
density(x, vars_response = "CPI")

# Check out the constant's densities
plot(density(x, vars_impulse = 1))

# Get the densities of variable three's first lag
density(x, vars = "FEDFUNDS-lag1")

# Get densities of lambda and the coefficients of dependent variable 2
density(x, vars = c("lambda", "UNRATE"))


BVAR documentation built on May 29, 2024, 5:34 a.m.