bvar simulates from the joint posterior distribution of the parameters
and latent variables and returns the posterior draws.
bvar(
data,
lags = 1L,
draws = 1000L,
burnin = 1000L,
thin = 1L,
prior_intercept = 10,
prior_phi = specify_prior_phi(data = data, lags = lags, prior = "HS"),
prior_sigma = specify_prior_sigma(data = data, type = "factor", quiet = TRUE),
sv_keep = "last",
expert_huge = FALSE,
quiet = FALSE,
startvals = list()
)An object of type bayesianVARs_bvar, a list containing the following
objects:
PHI: A bayesianVARs_coef object, an array, containing the posterior draws
of the VAR coefficients (including the intercept).
U: A bayesianVARs_draws object, a matrix, containing the posterior draws
of the contemporaneous coefficients (if cholesky decomposition for sigma is
specified).
logvar: A bayesianVARs_draws object containing the log-variance draws.
sv_para: A baysesianVARs_draws object containing the posterior draws of
the stochastic volatility related parameters.
phi_hyperparameter: A matrix containing the posterior draws of the
hyperparameters of the conditional normal prior on the VAR coefficients.
u_hyperparameter: A matrix containing the posterior draws of the
hyperparameters of the conditional normal prior on U (if cholesky
decomposition for sigma is specified).
bench: proc_time object containing the run time of the sampler.
V_prior: An array containing the posterior draws of the variances of the
conditional normal prior on the VAR coefficients.
facload: A bayesianVARs_draws object, an array, containing draws from the
posterior distribution of the factor loadings matrix (if factor
decomposition for sigma is specified).
fac: A bayesianVARs_draws object, an array, containing factor draws from
the posterior distribution (if factor decomposition for sigma is specified).
Y: Matrix containing the dependent variables used for estimation.
X matrix containing the lagged values of the dependent variables, i.e.
the covariates.
lags: Integer indicating the lag order of the VAR.
intercept: Logical indicating whether a constant term is included.
heteroscedastic logical indicating whether heteroscedasticity is assumed.
Yraw: Matrix containing the dependent variables, including the initial
'lags' observations.
Traw: Integer indicating the total number of observations.
sigma_type: Character specifying the decomposition of the
variance-covariance matrix.
datamat: Matrix containing both 'Y' and 'X'.
config: List containing information on configuration parameters.
Data matrix (can be a time series object). Each of \(M\) columns is assumed to contain a single time-series of length \(T\).
Integer indicating the order of the VAR, i.e. the number of lags of the dependent variables included as predictors.
single integer indicating the number of draws after the burnin
single integer indicating the number of draws discarded as burnin
single integer. Every \(thin\)th draw will be stored. Default is
thin=1L.
Either prior_intercept=FALSE and no constant
term (intercept) will be included. Or a numeric vector of length \(M\)
indicating the (fixed) prior standard deviations on the constant term. A
single number will be recycled accordingly. Default is
prior_intercept=10.
bayesianVARs_prior_phi object specifying prior for the
reduced form VAR coefficients. Best use constructor
specify_prior_phi.
bayesianVARs_prior_sigma object specifying prior for
the variance-covariance matrix of the VAR. Best use constructor
specify_prior_sigma.
String equal to "all" or "last". In case of
sv_keep = "last", the default, only draws for the very last
log-variance \(h_T\) are stored.
logical value indicating whether to use a specific algorithm for huge VARs. Only possible if a factor structure for the errors is specified. See section MCMC algorithm below for more details.
logical value indicating whether information about the progress
during sampling should be displayed during sampling (default is
TRUE).
optional list with starting values.
To sample efficiently the reduced-form VAR
coefficients assuming a factor structure for the errors, the equation
per equation algorithm in Kastner & Huber (2020) is implemented. The factor
structure has the advantage that an algorithm for sampling from
high-dimensional Gaussian distributions can be exploited by setting
expert_huge = TRUE. However, this speeds up computations only if \(K >
T\), i.e. the number of coefficients per equations exceeds the number of
observations. All parameters and latent variables associated with the
factor-structure are sampled using package
factorstochvol-package's function update_fsv
callable on the C-level only.
To sample efficiently the reduced-form VAR coefficients, assuming a
cholesky-structure for the errors, the corrected triangular algorithm in
Carriero et al. (2021) is implemented. The SV parameters and latent
variables are sampled using package stochvol's
update_fast_sv function. The precision parameters,
i.e. the free off-diagonal elements in \(\boldsymbol{U}\), can be sampled
using Bayesian linear regression methods, see Cogley and
Sargent (2005).
The VAR(p) model is of the following form: \( \boldsymbol{y}^\prime_t = \boldsymbol{\iota}^\prime + \boldsymbol{x}^\prime_t\boldsymbol{\Phi} + \boldsymbol{\epsilon}^\prime_t\), where \(\boldsymbol{y}_t\) is a \(M\)-dimensional vector of dependent variables and \(\boldsymbol{\epsilon}_t\) is the error term of the same dimension. \(\boldsymbol{x}_t\) is a \(K=pM\)-dimensional vector containing lagged/past values of the dependent variables \(\boldsymbol{y}_{t-l}\) for \(l=1,\dots,p\) and \(\boldsymbol{\iota}\) is a constant term (intercept) of dimension \(M\times 1\). The reduced-form coefficient matrix \(\boldsymbol{\Phi}\) is of dimension \(K \times M\).
bvar offers two different specifications for the errors: The user can
choose between a factor stochastic volatility structure or a cholesky
stochastic volatility structure. In both cases the disturbances
\(\boldsymbol{\epsilon}_t\) are assumed to follow a \(M\)-dimensional
multivariate normal distribution with zero mean and variance-covariance matrix
\(\boldsymbol{\Sigma}_t\). In case of the
cholesky specification \(\boldsymbol{\Sigma}_t = \boldsymbol{U}^{\prime -1} \boldsymbol{D}_t
\boldsymbol{U}^{-1}\), where \(\boldsymbol{U}^{-1}\) is upper unitriangular (with ones on
the diagonal). The diagonal matrix \(\boldsymbol{D}_t\) depends upon latent
log-variances, i.e. \(\boldsymbol{D}_t=diag(exp(h_{1t}),\dots,
exp(h_{Mt})\). The log-variances follow a priori independent autoregressive
processes \(h_{it}\sim N(\mu_i + \phi_i(h_{i,t-1}-\mu_i),\sigma_i^2)\) for
\(i=1,\dots,M\). In case of the factor structure,
\(\boldsymbol{\Sigma}_t = \boldsymbol{\Lambda} \boldsymbol{V}_t \boldsymbol{\Lambda}^\prime +
\boldsymbol{G}_t\). The diagonal matrices \(\boldsymbol{V}_t\) and
\(\boldsymbol{G}_t\) depend upon latent log-variances, i.e.
\(\boldsymbol{G}_t=diag(exp(h_{1t}),\dots, exp(h_{Mt})\) and
\(\boldsymbol{V}_t=diag(exp(h_{M+1,t}),\dots, exp(h_{M+r,t})\). The
log-variances
follow a priori independent autoregressive processes \(h_{it}\sim N(\mu_i +
\phi_i(h_{i,t-1}-\mu_i),\sigma_i^2)\) for \(i=1,\dots,M\) and
\(h_{M+j,t}\sim N(\phi_ih_{M+j,t-1},\sigma_{M+j}^2)\) for \(j=1,\dots,r\).
Gruber, L. and Kastner, G. (2025). Forecasting macroeconomic data with Bayesian VARs: Sparse or dense? It depends! International Journal of Forecasting. tools:::Rd_expr_doi("10.1016/j.ijforecast.2025.02.001").
Kastner, G. and Huber, F. Sparse (2020). Bayesian vector autoregressions in huge dimensions. Journal of Forecasting. 39, 1142--1165, tools:::Rd_expr_doi("10.1002/for.2680").
Kastner, G. (2019). Sparse Bayesian Time-Varying Covariance Estimation in Many Dimensions Journal of Econometrics, 210(1), 98--115, tools:::Rd_expr_doi("10.1016/j.jeconom.2018.11.007").
Carriero, A. and Chan, J. and Clark, T. E. and Marcellino, M. (2021). Corrigendum to “Large Bayesian vector autoregressions with stochastic volatility and non-conjugate priors” [J. Econometrics 212 (1) (2019) 137–154]. Journal of Econometrics, tools:::Rd_expr_doi("10.1016/j.jeconom.2021.11.010").
Cogley, S. and Sargent, T. (2005). Drifts and volatilities: monetary policies and outcomes in the post WWII US. Review of Economic Dynamics, 8, 262--302, tools:::Rd_expr_doi("10.1016/j.red.2004.10.009").
Hosszejni, D. and Kastner, G. (2021). Modeling Univariate and Multivariate Stochastic Volatility in R with stochvol and factorstochvol. Journal of Statistical Software, 100, 1–-34. tools:::Rd_expr_doi("10.18637/jss.v100.i12").
Helpers for prior configuration: specify_prior_phi(), specify_prior_sigma().
Plotting: plot.bayesianVARs_bvar().
Extractors: coef.bayesianVARs_bvar(), vcov.bayesianVARs_bvar().
'stable' bvar: stable_bvar().
summary method: summary.bayesianVARs_bvar().
predict method: predict.bayesianVARs_bvar().
fitted method: fitted.bayesianVARs_bvar().
# Access a subset of the usmacro_growth dataset
data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")]
# Estimate a model
mod <- bvar(data, sv_keep = "all", quiet = TRUE)
# Plot
plot(mod)
# Summary
summary(mod)
Run the code above in your browser using DataLab