| Title: | Bayesian Forecasting with Large Vector Autoregressions |
|---|---|
| Description: | Provides fast and efficient procedures for Bayesian estimation and forecasting using state-of-the-art Vector Autoregressions. This package includes the model proposed by Chan (2020) <doi:10.1080/07350015.2018.1451336>, that is, a Bayesian Vector Autoregression with Minnesota priors and a flexible structure of the error term specification. The latter includes: conditional multivariate normal or Student’s t distributions, as well as homoskedastic or heteroskedastic specifications with a common volatility modelled by centred or non-centred Stochastic Volatility. Additionally, the package facilitates predictive analyses using density forecasting and forecast-error variance decompositions. All this is complemented by simple workflows, useful plots and summary functions, and comprehensive documentation. The 'bvars' package aligns with R packages 'bsvars' by Woźniak (2024) <doi:10.32614/CRAN.package.bsvars>, 'bsvarSIGNs' by Wang & Woźniak (2025) <doi:10.32614/CRAN.package.bsvarSIGNs>, and 'bpvars' by Woźniak (2025) <doi:10.32614/CRAN.package.bpvars> regarding objects, workflows, and code structure, and they constitute an integrated toolset. |
| Authors: | Rui Liu [aut] (ORCID: <https://orcid.org/0009-0008-9348-8581>), Andrés Ramirez Hassan [aut] (ORCID: <https://orcid.org/0000-0002-0467-7903>), Tomasz Woźniak [aut, cre] (ORCID: <https://orcid.org/0000-0003-2212-2378>) |
| Maintainer: | Tomasz Woźniak <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0.9000 |
| Built: | 2026-06-09 07:59:38 UTC |
| Source: | https://github.com/bsvars/bvars |
Provides fast and efficient procedures for Bayesian estimation and forecasting using state-of-the-art Vector Autoregressions. This package includes the model proposed by Chan (2020) <doi:10.1080/07350015.2018.1451336>, that is, a Bayesian Vector Autoregression with Minnesota priors and a flexible structure of the error term specification. The latter includes: conditional multivariate normal or Student’s t distributions, as well as homoskedastic or heteroskedastic specifications with a common volatility modelled by centred or non-centred Stochastic Volatility. Additionally, the package facilitates predictive analyses using density forecasting and forecast-error variance decompositions. All this is complemented by simple workflows, useful plots and summary functions, and comprehensive documentation. The 'bvars' package aligns with R packages 'bsvars' by Woźniak (2024) <doi:10.32614/CRAN.package.bsvars>, 'bsvarSIGNs' by Wang & Woźniak (2025) <doi:10.32614/CRAN.package.bsvarSIGNs>, and 'bpvars' by Woźniak (2025) <doi:10.32614/CRAN.package.bpvars> regarding objects, workflows, and code structure, and they constitute an integrated toolset.
Models. All the BVAR models in this package are specified by two equations, including the reduced form equation:
where is an NxT matrix of dependent variables,
is a KxT matrix of explanatory variables,
is an NxT matrix of reduced form error terms,
and is an NxK matrix of autoregressive slope coefficients and
parameters on deterministic terms in .
This package assumes that the error matrix follows a matrix normal distribution:
where is the NxN covariance matrix of the error term at
time , and is a TxT diagonal matrix.
The diagonal elements of determine the specification of the error
term covariance structure. Specifically, the error term at time follows
the multivariate normal distribution
where the scalar processes and determine the
diagonal elements of . The process specifies
conditional variance and includes three options:
homoskedastic error term
estimated and following non-centred stochastic volatility
estimated and following centred stochastic volatility
The process specifies the conditional distribution of the error
term and includes two options:
Gaussian error term specification
estimated and following a priori an inverse gamma 2
distribution , where is
a degrees of freedom parameter
Prior distributions.
The autoregressive matrix is assigned matrix-variate normal distribution:
with the mean matrix , and covariance matrices
and
defining the row- and column-covariance structures.
This is complemented by the inverse Wishart prior for the error term covariance :
with the scale matrix and degrees of freedom .
This package is currently in active development. Your comments, suggestions and requests are warmly welcome!
Rui Liu [email protected], Andres Ramirez Hassan [email protected], Tomasz Woźniak [email protected]
Chan (2020) Large Bayesian VARs: A Flexible Kronecker Error Covariance Structure, Journal of Business and Economic Statistics, 38(1), 68–79, <doi:10.1080/07350015.2018.1451336>.
Useful links:
Report bugs at https://github.com/bsvars/bvars/issues
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post
Each of the draws from the posterior estimation of the BVAR model is transformed into a draw from the data predictive density.
## S3 method for class 'PosteriorBVAR' compute_fitted_values(posterior)## S3 method for class 'PosteriorBVAR' compute_fitted_values(posterior)
posterior |
posterior estimation outcome - an object of class
|
An object of class PosteriorFitted, that is, an NxTxS
array with attribute PosteriorFitted containing S draws from
the data predictive density.
Tomasz Woźniak [email protected]
spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model fitt = compute_fitted_values(post) # fitted values # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 5) |> compute_fitted_values() -> fittspec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model fitt = compute_fitted_values(post) # fitted values # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 5) |> compute_fitted_values() -> fitt
Each of the draws from the posterior estimation of models from the package bvars is transformed into a draw from the posterior distribution of the structural shocks.
compute_shocks(posterior)compute_shocks(posterior)
posterior |
posterior estimation outcome obtained by running the
|
An object of class PosteriorShocks, that is, an NxTxS array
with attribute PosteriorShocks containing S draws of the shocks.
Tomasz Woźniak [email protected]
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model shoc = compute_shocks(post) # compute shocks plot(shoc) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_shocks() |> plot()# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model shoc = compute_shocks(post) # compute shocks plot(shoc) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_shocks() |> plot()
Each of the draws from the posterior estimation of the BAVR model is transformed into a draw from the posterior distribution of the shocks.
## S3 method for class 'PosteriorBVAR' compute_shocks(posterior)## S3 method for class 'PosteriorBVAR' compute_shocks(posterior)
posterior |
posterior estimation outcome - an object of class
|
An object of class PosteriorShocks, that is, an NxTxS
array with attribute PosteriorShocks containing S draws of the shocks.
Tomasz Woźniak [email protected]
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model shoc = compute_shocks(post) # compute shocks # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_shocks() -> shoc# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model shoc = compute_shocks(post) # compute shocks # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_shocks() -> shoc
Each of the draws from the posterior estimation of the Vector Autoregression is transformed into a draw from the posterior distribution of the forecast error variance decomposition.
## S3 method for class 'PosteriorBVAR' compute_variance_decompositions(posterior, horizon)## S3 method for class 'PosteriorBVAR' compute_variance_decompositions(posterior, horizon)
posterior |
posterior estimation outcome obtained by running the |
horizon |
a positive integer number denoting the forecast horizon for the forecast error variance decomposition computations. |
An object of class PosteriorFEVD, that is, an NxNx(horizon+1)xS
array with attribute PosteriorFEVD containing S draws of the
forecast error variance decomposition.
Tomasz Woźniak [email protected]
Kilian, L., & Lütkepohl, H. (2017). Structural VAR Tools, Chapter 4, In: Structural vector autoregressive analysis. Cambridge University Press.
spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model fevd = compute_variance_decompositions(post, horizon = 4) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_variance_decompositions(horizon = 4) -> fevdspec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model fevd = compute_variance_decompositions(post, horizon = 4) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> compute_variance_decompositions(horizon = 4) -> fevd
Estimates the model by Chan (2020) <doi:10.1080/07350015.2018.1451336>, that is, a Bayesian Vector Autoregression with Minnesota priors and a flexible structure of the error term specification. The latter includes: conditional multivariate normal or Student’s t distributions, as well as homoskedastic or heteroskedastic specifications with a common volatility modelled by centred or non-centred Stochastic Volatility. The estimation is conducted via an efficient Gibbs sampler employing frontier numerical techniques and algorithms written in C++ for excellent computational speed.
## S3 method for class 'BVAR' estimate(specification, S, thin = 1, show_progress = TRUE)## S3 method for class 'BVAR' estimate(specification, S, thin = 1, show_progress = TRUE)
specification |
an object of class |
S |
a positive integer, the number of posterior draws to be generated |
thin |
a positive integer, specifying the frequency of MCMC output thinning |
show_progress |
a logical value, if |
An object of class PosteriorBVAR containing the Bayesian
estimation output and containing two elements:
posterior a list with a collection of S draws from the
posterior distribution generated via Gibbs sampler containing:
an NxKxS array with the posterior draws for matrix
an NxNxS array with the posterior draws for matrix
a KxKxS array with the posterior draws for the hyper-parameter
matrix
last_draw an object of class BVAR with the last draw of the
current MCMC run as the starting value to be passed to the continuation of
the MCMC estimation using estimate().
Rui Liu [email protected], Andres Ramirez Hassan [email protected] & Tomasz Woźniak [email protected]
Barndorff-Nielsen, Blaesild, Jensen, Jorgensen (1982) Exponential Transformation Models, Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences, 379, 41–-65, <doi:10.1098/rspa.1982.0004>.
Chan (2020) Large Bayesian VARs: A Flexible Kronecker Error Covariance Structure, Journal of Business and Economic Statistics, 38(1), 68–79, <doi:10.1080/07350015.2018.1451336>.
Hamura, Irie, Sugasawa (2024) Gibbs Sampler for Matrix Generalized Inverse Gaussian Distributions, Journal of Computational and Graphical Statistics, 33(2), 331–340, <doi:10.1080/10618600.2023.2258186>.
Thabane, Safiul Haq (2004) On the Matrix-Variate Generalized Hyperbolic Distribution and Its Bayesian Applications, Statistics: A Journal of Theoretical and Applied Statistics, 38(6), 511–526, <doi:10.1080/02331880412331319279>.
Woźniak (2016) Bayesian Vector Autoregressions, Australian Economic Review, 49(3), 365–380, <doi:10.1111/1467-8462.12179>.
specify_bvar, specify_posterior_bvar
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post
Estimates the model by Chan (2020) <doi:10.1080/07350015.2018.1451336>, that is, a Bayesian Vector Autoregression with Minnesota priors and a flexible structure of the error term specification. The latter includes: conditional multivariate normal or Student’s t distributions, as well as homoskedastic or heteroskedastic specifications with a common volatility modelled by centred or non-centred Stochastic Volatility. The estimation is conducted via an efficient Gibbs sampler employing frontier numerical techniques and algorithms written in C++ for excellent computational speed.
## S3 method for class 'PosteriorBVAR' estimate(specification, S, thin = 1, show_progress = TRUE)## S3 method for class 'PosteriorBVAR' estimate(specification, S, thin = 1, show_progress = TRUE)
specification |
an object of class |
S |
a positive integer, the number of posterior draws to be generated |
thin |
a positive integer, specifying the frequency of MCMC output thinning |
show_progress |
a logical value, if |
An object of class PosteriorBVAR containing the Bayesian
estimation output and containing two elements:
posterior a list with a collection of S draws from the
posterior distribution generated via Gibbs sampler containing:
an NxKxS array with the posterior draws for matrix
an NxNxS array with the posterior draws for matrix
a KxKxS array with the posterior draws for the hyper-parameter
matrix
last_draw an object of class BVAR with the last draw of the
current MCMC run as the starting value to be passed to the continuation of
the MCMC estimation using estimate().
Rui Liu [email protected], Andres Ramirez Hassan [email protected] & Tomasz Woźniak [email protected]
Barndorff-Nielsen, Blaesild, Jensen, Jorgensen (1982) Exponential Transformation Models, Proceedings of the Royal Society of London. A. Mathematical and Physical Sciences, 379, 41–-65, <doi:10.1098/rspa.1982.0004>.
Chan (2020) Large Bayesian VARs: A Flexible Kronecker Error Covariance Structure, Journal of Business and Economic Statistics, 38(1), 68–79, <doi:10.1080/07350015.2018.1451336>.
Hamura, Irie, Sugasawa (2024) Gibbs Sampler for Matrix Generalized Inverse Gaussian Distributions, Journal of Computational and Graphical Statistics, 33(2), 331–340, <doi:10.1080/10618600.2023.2258186>.
Thabane, Safiul Haq (2004) On the Matrix-Variate Generalized Hyperbolic Distribution and Its Bayesian Applications, Statistics: A Journal of Theoretical and Applied Statistics, 38(6), 511–526, <doi:10.1080/02331880412331319279>.
Woźniak (2016) Bayesian Vector Autoregressions, Australian Economic Review, 49(3), 365–380, <doi:10.1111/1467-8462.12179>.
specify_bvar, specify_posterior_bvar
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) -> post
Samples from the joint predictive density of all of the dependent variables for the model by Chan (2020) <doi:10.1080/07350015.2018.1451336>, that is, a Bayesian Vector Autoregression with Minnesota priors and a flexible structure of the error term specification. The latter includes: conditional multivariate normal or Student’s t distributions, as well as homoskedastic or heteroskedastic specifications with a common volatility modelled by centred or non-centred Stochastic Volatility.
## S3 method for class 'PosteriorBVAR' forecast( object, horizon = 1, exogenous_forecast = NULL, conditional_forecast = NULL, ... )## S3 method for class 'PosteriorBVAR' forecast( object, horizon = 1, exogenous_forecast = NULL, conditional_forecast = NULL, ... )
object |
posterior estimation outcome - an object of class
|
horizon |
a positive integer, specifying the forecasting horizon. |
exogenous_forecast |
a matrix of dimension |
conditional_forecast |
a |
... |
not used |
A list of class Forecasts containing the
draws from the predictive density and data. The output list includes element:
an NxTxS array with the draws from predictive density
an NxhorizonxS array with the mean of the predictive density
an NxNxhorizonxS array with the covariance of the predictive density
an matrix with the data on dependent variables
Rui Liu [email protected], Andres Ramirez Hassan [email protected] & Tomasz Woźniak [email protected]
spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 5) # estimate the model pred = forecast(post, 4) # forecast 1 year ahead # workflow with the pipe |> ############################################################ set.seed(123) us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 5) |> forecast(horizon = 4) -> predspec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 5) # estimate the model pred = forecast(post, 4) # forecast 1 year ahead # workflow with the pipe |> ############################################################ set.seed(123) us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 5) |> forecast(horizon = 4) -> pred
Samples random numbers from the matrix-variate normal distribution
rmatnorm1(M, V, S)rmatnorm1(M, V, S)
M |
a real-valued matrix of the expected values |
V |
a positive definite symmetric matrix of column-specific covariance |
S |
a positive definite symmetric matrix of row-specific covariance |
a matrix - a draw from the matrix-variate normal distribution
rmatnorm1(matrix(0, 2, 3), diag(2), diag(3))rmatnorm1(matrix(0, 2, 3), diag(2), diag(3))
BVAR modelThe class BVAR presents complete specification for the BVAR model.
pa non-negative integer specifying the autoregressive lag order of the model.
prioran object PriorBVAR with the prior specification.
data_matricesan object DataMatricesBSVAR with the data matrices.
starting_valuesan object StartingValuesBVAR with the starting values.
new()
Create a new specification of the BVAR model.
specify_bvar$new(
data,
p = 1L,
exogenous = NULL,
common_volatility = c("homoskedastic", "ncSV", "cSV"),
distribution = c("norm", "t"),
stationary = rep(FALSE, ncol(data))
)dataa (T+p)xN matrix with time series data.
pa positive integer providing model's autoregressive lag order.
exogenousa (T+p)xd matrix of exogenous variables.
common_volatilitya character string specifying the common volatility
component of the error term covariance matrix. It can take three values:
homoskedastic - the model assumes homoskedastic errors,
ncSV - the model assumes non-centred stochastic volatility, and
cSV - the model assumes centred stochastic volatility.
distributiona character string specifying the conditional distribution
of structural shocks. Value "norm" sets it to the normal distribution,
while value "t" sets the Student-t distribution.
stationaryan N logical vector - its element set to
FALSE sets the prior mean for the autoregressive parameters of the
Nth equation to the white noise process, otherwise to random walk.
A new complete specification for the BVAR model.
get_normal()
Returns the logical value of whether the conditional shock distribution is normal.
specify_bvar$get_normal()
spec = specify_bvar$new(us_macro_chan) spec$get_normal()
get_homoskedastic()
Returns the logical value of whether the common volatility is homoskedastic.
specify_bvar$get_homoskedastic()
spec = specify_bvar$new(us_macro_chan) spec$get_homoskedastic()
get_centred_sv()
Returns the logical value of whether the common volatility is centred Stochastic Volatility
specify_bvar$get_centred_sv()
spec = specify_bvar$new(us_macro_chan) spec$get_centred_sv()
get_data_matrices()
Returns the data matrices as the DataMatricesBSVAR object.
specify_bvar$get_data_matrices()
spec = specify_bvar$new(us_macro_chan) spec$get_data_matrices()
get_prior()
Returns the prior specification as the PriorBVAR object.
specify_bvar$get_prior()
spec = specify_bvar$new(us_macro_chan) spec$get_prior()
get_starting_values()
Returns the starting values as the StartingValuesBVAR object.
specify_bvar$get_starting_values()
spec = specify_bvar$new(us_macro_chan) spec$get_starting_values()
clone()
The objects of this class are cloneable with this method.
specify_bvar$clone(deep = FALSE)
deepWhether to make a deep clone.
spec = specify_bvar$new(us_macro_chan) ## ------------------------------------------------ ## Method `specify_bvar$get_normal` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_normal() ## ------------------------------------------------ ## Method `specify_bvar$get_homoskedastic` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_homoskedastic() ## ------------------------------------------------ ## Method `specify_bvar$get_centred_sv` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_centred_sv() ## ------------------------------------------------ ## Method `specify_bvar$get_data_matrices` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_data_matrices() ## ------------------------------------------------ ## Method `specify_bvar$get_prior` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_prior() ## ------------------------------------------------ ## Method `specify_bvar$get_starting_values` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_starting_values()spec = specify_bvar$new(us_macro_chan) ## ------------------------------------------------ ## Method `specify_bvar$get_normal` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_normal() ## ------------------------------------------------ ## Method `specify_bvar$get_homoskedastic` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_homoskedastic() ## ------------------------------------------------ ## Method `specify_bvar$get_centred_sv` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_centred_sv() ## ------------------------------------------------ ## Method `specify_bvar$get_data_matrices` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_data_matrices() ## ------------------------------------------------ ## Method `specify_bvar$get_prior` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_prior() ## ------------------------------------------------ ## Method `specify_bvar$get_starting_values` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) spec$get_starting_values()
PosteriorBVAR
The class PosteriorBVAR contains posterior output and the
specification including the last MCMC draw for the BVAR model.
Note that due to the thinning of the MCMC output the starting value in element
last_draw might not be equal to the last draw provided in element
posterior.
last_drawan object of class BVAR with the last draw of
the current MCMC run as the starting value to be passed to the
continuation of the MCMC estimation using estimate().
posteriora list containing Bayesian estimation output collected
in elements A, Sigma, and V.
new()
Create a new posterior output PosteriorBVAR.
specify_posterior_bvar$new(specification_bvar, posterior_bvar)
specification_bvaran object of class BVAR with the
last draw of the current MCMC run as the starting value.
posterior_bvara list containing Bayesian estimation output
collected in elements A, Sigma, and V.
A posterior output PosteriorBVAR.
get_posterior()
Returns a list containing Bayesian estimation output collected in elements
A, Sigma, and V.
specify_posterior_bvar$get_posterior()
spec = specify_bvar$new(us_macro_chan) post = estimate(spec, 5) post$get_posterior()
get_last_draw()
Returns an object of class BVAR with the last draw of the
current MCMC run as the starting value to be passed to the continuation
of the MCMC estimation using estimate().
specify_posterior_bvar$get_last_draw()
spec = specify_bvar$new(us_macro_chan) burn = estimate(spec, 5) post = estimate(burn, 5)
clone()
The objects of this class are cloneable with this method.
specify_posterior_bvar$clone(deep = FALSE)
deepWhether to make a deep clone.
# This is a function that is used within estimate() spec = specify_bvar$new(us_macro_chan) post = estimate(spec, 5) class(post) ## ------------------------------------------------ ## Method `specify_posterior_bvar$get_posterior` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) post = estimate(spec, 5) post$get_posterior() ## ------------------------------------------------ ## Method `specify_posterior_bvar$get_last_draw` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) burn = estimate(spec, 5) post = estimate(burn, 5)# This is a function that is used within estimate() spec = specify_bvar$new(us_macro_chan) post = estimate(spec, 5) class(post) ## ------------------------------------------------ ## Method `specify_posterior_bvar$get_posterior` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) post = estimate(spec, 5) post$get_posterior() ## ------------------------------------------------ ## Method `specify_posterior_bvar$get_last_draw` ## ------------------------------------------------ spec = specify_bvar$new(us_macro_chan) burn = estimate(spec, 5) post = estimate(burn, 5)
PriorBVAR
The class PriorBVAR presents a prior specification for the BVAR model.
#' The Model. All the BVAR models in this package are specified by two equations, including the reduced form equation:
where is an NxT matrix of dependent variables,
is a KxT matrix of explanatory variables,
is an NxT matrix of reduced form error terms,
and is an NxK matrix of autoregressive slope coefficients and
parameters on deterministic terms in .
This package assumes that the error matrix follows a matrix normal distribution:
where is the NxN covariance matrix of the error term at
time , and is a TxT diagonal matrix.
The diagonal elements of determine the specification of the error
term covariance structure. Specifically, the error term at time follows
the multivariate normal distribution
where the scalar processes and determine the
diagonal elements of . The process specifies
conditional variance and includes three options:
homoskedastic error term
estimated and following non-centred stochastic volatility
estimated and following centred stochastic volatility
The process specifies the conditional distribution of the error
term and includes two options:
Gaussian error term specification
estimated and following a priori an inverse gamma 2
distribution , where is
a degrees of freedom parameter
Prior distributions.
The autoregressive matrix is assigned matrix-variate normal distribution:
with the mean matrix , and covariance matrices
and
defining the row- and column-covariance structures.
This is complemented by the inverse Wishart prior for the error term covariance :
with the scale matrix and degrees of freedom .
Aa real-valued NxK matrix, the mean matrix of
the matrix-variate normal prior distribution for the parameter
matrix .
Sa NxN positive definite scale matrix of the
Inverse Wishart prior distribution for the error term covariance
matrix .
nua positive scalar, shape parameter of the Inverse
Wishart prior distribution for the error term covariance
matrix .
Psia KxK scale matrix of the matrix
generalized inverse Gaussian distribution for the equation-specific prior
covariance
Gammaa KxK scale matrix of the matrix
generalized inverse Gaussian distribution for the equation-specific prior
covariance
lambdaa positive scalar shape parameter of the
matrix generalized inverse Gaussian distribution for the equation-specific
prior covariance
sv_aa positive scalar, the shape parameter of the gamma prior in the hierarchical prior for the common stochastic volatility.
sv_sa positive scalar, the scale parameter of the gamma prior in the hierarchical prior for the common stochastic volatility.
new()
Create a new prior specification PriorBVAR.
specify_prior_bvar$new( N, p, d = 0, stationary = rep(FALSE, N), is_homoskedastic = TRUE )
Na positive integer - the number of dependent variables in the model.
pa positive integer - the autoregressive lag order of the VAR model.
da positive integer - the number of exogenous variables in the model.
stationaryan N logical vector - its element set to
FALSE sets the prior mean for the autoregressive parameters of the
Nth equation to the white noise process, otherwise to random walk.
is_homoskedastica logical scalar - if TRUE the model assumes
homoskedastic errors, otherwise it assumes stochastic volatility.
A new prior specification PriorBVAR.
# a prior for 3-variable example with one lag and stationary data prior = specify_prior_bvar$new(N = 3, p = 1, stationary = rep(TRUE, 3)) prior$A # show autoregressive prior mean
get_prior()
Returns the elements of the prior specification PriorBVAR as
a list.
specify_prior_bvar$get_prior()
# a prior for 3-variable example with four lags prior = specify_prior_bvar$new(N = 3, p = 4) prior$get_prior() # show the prior as list
clone()
The objects of this class are cloneable with this method.
specify_prior_bvar$clone(deep = FALSE)
deepWhether to make a deep clone.
prior = specify_prior_bvar$new(N = 3, p = 1) # a prior for 3-variable example with one lag prior$A # show autoregressive prior mean ## ------------------------------------------------ ## Method `specify_prior_bvar$new` ## ------------------------------------------------ # a prior for 3-variable example with one lag and stationary data prior = specify_prior_bvar$new(N = 3, p = 1, stationary = rep(TRUE, 3)) prior$A # show autoregressive prior mean ## ------------------------------------------------ ## Method `specify_prior_bvar$get_prior` ## ------------------------------------------------ # a prior for 3-variable example with four lags prior = specify_prior_bvar$new(N = 3, p = 4) prior$get_prior() # show the prior as listprior = specify_prior_bvar$new(N = 3, p = 1) # a prior for 3-variable example with one lag prior$A # show autoregressive prior mean ## ------------------------------------------------ ## Method `specify_prior_bvar$new` ## ------------------------------------------------ # a prior for 3-variable example with one lag and stationary data prior = specify_prior_bvar$new(N = 3, p = 1, stationary = rep(TRUE, 3)) prior$A # show autoregressive prior mean ## ------------------------------------------------ ## Method `specify_prior_bvar$get_prior` ## ------------------------------------------------ # a prior for 3-variable example with four lags prior = specify_prior_bvar$new(N = 3, p = 4) prior$get_prior() # show the prior as list
StartingValuesBVAR
The class StartingValuesBVAR presents starting values for the BVAR model.
Aan NxK matrix of starting values for the autoregressive
matrix .
Sigmaan NxN matrix of starting values for the error term
covariance .
Va KxK matrix of starting values for the prior
equation-specific covariance of the hierarchical prior distribution
for matrix .
han T-vector with the starting values of the
log-volatility processes.
rhoa scalalr for the SV autoregressive parameter.
omegaa scalar for the SV process conditional standard deviation.
sigma2va scalar for SV process conditional variances.
Sa T integer vector with the auxiliary mixture
component indicator.
sigma2_omegaa scalar for the variance of the zero-mean
normal prior for .
s_a positive scalar with the scale of the gamma prior of the
hierarchical prior for .
lambdaa T-vetor of starting values for latent variable.
dfa scalar greater than 2 with the starting value for the degrees of freedom parameter of the Student-t conditional distribution of error term.
new()
Create new starting values StartingValuesBVAR.
specify_starting_values_bvar$new( N, p, T, d = 0, is_homoskedastic = TRUE, is_normal = TRUE, ar_sigma2 = rep(1, N), kappa = c(0.2^2, 10^2) )
Na positive integer - the number of dependent variables in the model.
pa positive integer - the autoregressive lag order of the BVAR model.
Ta positive integer - the number of time periods in the data.
da positive integer - the number of exogenous variables in the model.
is_homoskedastica logical scalar - if TRUE the model assumes
homoskedastic errors, otherwise it assumes stochastic volatility.
is_normala logical scalar - if TRUE the model assumes normal
error term, otherwise, it assumes Student-t errors.
ar_sigma2a positive N-vector with the autoregressive variance
estimates for each variable to be used in the Minnesota prior for the autoregressive
parameters.
kappaa positive 2-vector with the hyperparameters of
the Minnesota prior for the autoregressive parameters - the first element
is the overall tightness hyperparameter, while the second element is the
tightness of the prior on the constant and exogenous variable coefficients.
Starting values StartingValuesBVAR.
# starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100)
get_starting_values()
Returns the elements of the starting values StartingValuesBVAR as a list.
specify_starting_values_bvar$get_starting_values()
# starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) sv$get_starting_values() # show starting values as list
set_starting_values()
Sets the elements of the starting values StartingValuesBVAR to
provided values.
specify_starting_values_bvar$set_starting_values(last_draw)
last_drawa list containing the last draw of elements A -
a KxN matrix, Sigma - an NxN matrix, and V -
a KxK matrix.
An object of class StartingValuesBVAR including the
last draw of the current MCMC as the starting value to be passed to the
continuation of the MCMC estimation using estimate().
# starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) # Modify the starting values by: sv_list = sv$get_starting_values() # getting them as list sv_list$A <- matrix(rnorm(12), 3, 4) # modifying the entry sv$set_starting_values(sv_list) # providing to the class object
clone()
The objects of this class are cloneable with this method.
specify_starting_values_bvar$clone(deep = FALSE)
deepWhether to make a deep clone.
# starting values for a 3-variable BVAR model. sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) ## ------------------------------------------------ ## Method `specify_starting_values_bvar$new` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) ## ------------------------------------------------ ## Method `specify_starting_values_bvar$get_starting_values` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) sv$get_starting_values() # show starting values as list ## ------------------------------------------------ ## Method `specify_starting_values_bvar$set_starting_values` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) # Modify the starting values by: sv_list = sv$get_starting_values() # getting them as list sv_list$A <- matrix(rnorm(12), 3, 4) # modifying the entry sv$set_starting_values(sv_list) # providing to the class object# starting values for a 3-variable BVAR model. sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) ## ------------------------------------------------ ## Method `specify_starting_values_bvar$new` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) ## ------------------------------------------------ ## Method `specify_starting_values_bvar$get_starting_values` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) sv$get_starting_values() # show starting values as list ## ------------------------------------------------ ## Method `specify_starting_values_bvar$set_starting_values` ## ------------------------------------------------ # starting values for a 3-variable BVAR model sv = specify_starting_values_bvar$new(N = 3, p = 4, T = 100) # Modify the starting values by: sv_list = sv$get_starting_values() # getting them as list sv_list$A <- matrix(rnorm(12), 3, 4) # modifying the entry sv$set_starting_values(sv_list) # providing to the class object
Provides posterior mean, standard deviations, as well as 5 and 95
percentiles of the parameters: autoregressive
parameters , and the covariance matrix .
## S3 method for class 'PosteriorBVAR' summary(object, ...)## S3 method for class 'PosteriorBVAR' summary(object, ...)
object |
an object of class PosteriorBVAR obtained using the
|
... |
additional arguments affecting the summary produced. |
A list reporting the posterior mean, standard deviations, as well as 5 and 95
percentiles of the parameters: autoregressive
parameters , and the covariance matrix ..
Tomasz Woźniak [email protected]
# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model summary(post) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> summary()# simple workflow ############################################################ spec = specify_bvar$new(us_macro_chan) # specify the model burn = estimate(spec, 5) # run the burn-in post = estimate(burn, 10) # estimate the model summary(post) # workflow with the pipe |> ############################################################ us_macro_chan |> specify_bvar$new() |> estimate(S = 5) |> estimate(S = 10) |> summary()
A system of 20 US macroeconomic aggregates used by Chan (2020).
data(us_macro_chan)data(us_macro_chan)
A matrix and a ts object with time series of 217 observations
on 20 variables:
Real gross domestic product
Consumer price index
Effective Federal funds rate
M2 money stock
Personal income
Real personal consumption expenditure
Industrial production index
Civilian unemployment rate
Housing starts
Producer price index
Personal consumption expenditures: chain-type price index
Average hourly earnings: manufacturing
MI money stock
10-Year Treasury constant maturity rate
Real gross private domestic investment
All employees: total nonfarm
ISM manufacturing: PMI composite index
ISM manufacturing: new orders index
Business sector: real output per hour of all Persons
Real stock prices (S& P 500 index divided by PCE index
The series are used and described by Chan (2020) in Appendix B of Supplementary Materials available at <doi:10.1080/07350015.2018.1451336>.
FRED Economic Database, Federal Reserve Bank of St. Louis, https://fred.stlouisfed.org/
Chan (2020) Large Bayesian VARs: A Flexible Kronecker Error Covariance Structure, Journal of Business and Economic Statistics, 38(1), 68–79, <doi:10.1080/07350015.2018.1451336>.
data(us_macro_chan) # upload the datadata(us_macro_chan) # upload the data