Calculates densities of hyperparameters or coefficient draws from Bayesian
VAR models generated via bvar
. Wraps standard
density
outputs into a list
.
# S3 method for bvar
density(x, vars = NULL, vars_response = NULL, vars_impulse = NULL, ...)# S3 method for bvar_density
plot(x, mar = c(2, 2, 2, 0.5), mfrow = c(length(x), 1), ...)
independent_index(var, n_vars, lag)
Returns a list with outputs of density
.
A bvar
object, obtained from bvar
.
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.
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.
Numeric vector. Margins for par
.
Numeric vector. Rows for par
.
Integer scalars. Retrieve the position of lag lag of variable var given n_vars total variables.
bvar
; density
# \donttest{
# 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"))
# }
Run the code above in your browser using DataLab