Estimates a Bayesian GVAR with either the Stochastic Search Variable Selection (SSVS), the Minnesota prior (MN), or the Normal-Gamma prior. All specifications can be estimated with stochastic volatility.
bgvar(Data, W, plag=1, draws=5000, burnin=5000, prior="NG", SV=TRUE, hold.out=0, thin=1,
hyperpara=NULL, eigen=FALSE, Ex=NULL, trend=FALSE, expert=NULL, verbose=TRUE)
Either a
list object
of length N
that contains the data. Each element of the list refers to a country/entity. The number of columns (i.e., variables) in each country model can be different. The T
rows (i.e., number of time observations), however, need to be the same for each country. Country and variable names are not allowed to contain a dot .
(i.e., a dot) since this is our naming convention.
matrix object
of dimension T
times K
, with K
denoting the sum of all endogenous variables of the system. The column names should consist of two parts, separated by a .
(i.e., a dot). The first part should denote the country / entity name and the second part the name of the variable. Country and variable names are not allowed to contain a .
(i.e., a dot).
An N times N weight matrix with 0 elements on the diagonal and row sums that sum up to unity or a list of weight matrices.
Number of lags used (the same for domestic, exogenous and weakly exogenous variables.). Default set to plag=1
.
Number of draws saved. Default set to draws=5000
.
Number of burn-ins. Default set to burnin=5000
.
Either SSVS
for the Stochastic Search Variable Selection prior, MN
for the Minnesota prior or NG
for the Normal-Gamma prior. See Details below.
If set to TRUE
, models are fitted with stochastic volatility using the stochvol
package. Due to storage issues, not the whole history of the T
variance covariance matrices are kept, only the median. Consequently, the BGVAR
package shows only one set of impulse responses (with variance covariance matrix based on mean sample point volatilities) instead of T
sets. Specify SV=FALSE
to turn SV off.
Defines the hold-out sample. Default without hold-out sample, thus set to zero.
Is a thinning interval of the MCMC chain. As a rule of thumb, workspaces get large if draws/thin>500. Default set to thin=1
.
Is a list object that defines the hyperparameters when the prior is set to either MN
, SSVS
or NG
.
a_1
is the prior hyperparameter for the inverted gamma prior (shape) (set a_1 = b_1 to a small value for the standard uninformative prior). Default is set to a_1=0.01
.
b_1
is the prior hyperparameter for the inverted gamma prior (rate). Default is set to b_1=0.01
.
prmean
Prior mean on the first lag of the autoregressive coefficients, standard value is prmean=1
for non-stationary data. Prior mean for the remaining autoregressive coefficients automatically set to 0.
bmu
If SV=TRUE
, this is the prior hyperparameter for the mean of the the mean of the log-volatilities. Default is bmu=0
.
Bmu
If SV=TRUE
, this is the prior hyperparameter for the variance of the mean of the log-volatilities. Default is Bmu=100
.
a0
If SV=TRUE
, this is the hyperparameter of the shape1 parameter for the Beta prior on the persistence parameter of the log-volatilities. Default is a0=25
.
b0
If SV=TRUE
, this is the hyperparameter of the shape2 parameter for the Beta prior on the persistence parameter of the log-volatilities. Default is b0=1.5
.
Bsigma
If SV=TRUE
, this is the hyperparameter for the Gamma prior on the variance of the log-volatilities. Default is set to Bsigma=1
.
"MN"
shrink1
Starting value of shrink1
. Default set to 0.1.
shrink2
Starting value of shrink2
. Default set to 0.2.
shrink3
Hyperparameter of shrink3
. Default set to 100.
shrink4
Starting value of shrink4
. Default set to 0.1.
"SSVS"
tau0
is the prior variance associated with the normal prior on the regression coefficients if a variable is NOT included (spike, tau0 should be close to zero).
tau1
is the prior variance associated with the normal prior on the regression coefficients if a variable is included (slab, tau1 should be large).
kappa0
is the prior variance associated with the normal prior on the covariances if a covariance equals zero (spike, kappa0 should be close to zero).
kappa1
is the prior variance associated with the normal prior on the covariances if a covariance is unequal to zero (slab, kappa1 should be large).
p_i
is the prior inclusion probability for each regression coefficient whether it is included in the model (default set to p_i=0.5
).
q_ij
is the prior inclusion probability for each covariance whether it is included in the model (default set to q_ij=0.5
).
"NG":
e_lambda
Prior hyperparameter for the Gamma prior on the lag-specific shrinkage components, standard value is e_lambda=1.5
.
d_lambda
Prior hyperparameter for the Gamma prior on the lag-specific shrinkage components, standard value is d_lambda=1
.
tau_theta
Parameter of the Normal-Gamma prior that governs the heaviness of the tails of the prior distribution. A value of tau_theta=1
would lead to the Bayesian LASSO. Default value differs per entity and set to tau_theta=1/log(M)
, where M
is the number of endogenous variables per entity.
sample_tau
If set to TRUE
tau_theta
is sampled.
Set to TRUE if you want to compute the largest eigenvalue of the companion matrix for each posterior draw. If the modulus of the eigenvalue is significantly larger than unity, the model is unstable. Unstable draws exceeding an eigenvalue of one are then excluded. If eigen
is set to a numeric value, then this corresponds to the maximum eigenvalue. The default is set to 1.05 (which excludes all posterior draws for which the eigenvalue of the companion matrix was larger than 1.05 in modulus).
For including truly exogenous variables to the model. Either a
list object
of maximum length N
that contains the data. Each element of the list refers to a country/entity and has to match the country/entity names in Data
. If no truly exogenous variables are added to the respective country/entity model, omit the entry. The T
rows (i.e., number of time observations), however, need to be the same for each country. Country and variable names are not allowed to contain a dot .
(i.e., a dot) since this is our naming convention.
matrix object
of dimension T
times number of truly exogenous variables. The column names should consist of two parts, separated by a .
(i.e., a dot). The first part should denote the country / entity name and the second part the name of the variable. Country and variable names are not allowed to contain a .
(i.e., a dot).
If set to TRUE
a deterministic trend is added to the country models.
Expert settings, must be provided as list. Default is set to NULL
.
variable.list
In case W
is a list of weight matrices, specify here which set of variables should be weighted by which weighting matrix. Default is NULL
.
OE.weights
Default value is set to NULL
. Can be used to provide information of how to handle additional country models (other entities). Additional country models can be used to endogenously determine variables that are (weakly) exogenous for the majority of the other country models. As examples, one could think of an additional oil price model (see also Mohaddes and Raissi 2019) or a model for the joint euro area monetary policy (see also Georgiadis 2015; Feldkircher, Gruber and Huber (2020)). The data for these additional country models has to be contained in Data
. The number of additional country models is unlimited. Each list entry of OE.weights
has to be named similar to the name of the additional country model contained in Data
. Each slot of OE.weight
has to contain the following information:
weights
Vector of weights with names relating to the countries for which data should be aggregated. Can also relate to a subset of countries contained in the data.
variables
Vector of variables names that should be included in the additional country model. Variables that are not contained in the data slot of the extra country model are assumed to be weakly exogenous for the additional country model (aggregated with weight
).
exo
Vector of variable names that should be fed into the other countries as (weakly) exogenous variables.
Wex.restr
Character vector containing variables that should only be specified as weakly exogenous if not contained as endogenous variable in a particular country. An example that has often been used in the literature is to place these restrictions on nominal exchange rates. Default is NULL
in which case all weakly exogenous variables are treated symmetrically.
save.country.store
If set to TRUE
then function also returns the container of all draws of the individual country models. Significantly raises object size of output and default is thus set to FALSE
.
use_R
Boolean whether estimation should fall back on R
version, otherwise Rcpp
version is used (default).
applyfun
In case use_R=TRUE
, this allows for user-specific apply function, which has to have the same interface than lapply
. If cores=NULL
then lapply
is used, if set to a numeric either parallel::parLapply()
is used on Windows platforms and parallel::mclapply()
on non-Windows platforms.
cores
Numeric specifying the number of cores which should be used, also all
and half
is possible. By default only one core is used.
If set to FALSE
it suppresses printing messages to the console.
Returns a list of class bgvar
with the following elements:
args
is a list object that contains the arguments submitted to function bgvar
.
xglobal
is a matrix object of dimension T times N (T # of observations, K # of variables in the system).
gW
is the global weight matrix. It is a list, with N
entries, each of which contains the weight matrix of each country.
country.res
is a matrix that contains the posterior mean of the country models' residuals. The residuals have been obtained as a running mean and thus always relate to the full set of posterior draws. This implies that in case you have opted for trimming the draws the residuals do not correspond to the posterior draws of the "trimmed" coefficients. This is a storage problem, rather than a statistical problem. Experiments, however, show that residual properties (autocorrelation, cross-sectional correlation) of trimmed and reported residuals are close.
stacked results
S_large
is a three-dimensional array (K times K times draws) of the (block-diagonal) posterior variance covariance matrix.
F_large
is a four-dimensional array (K times K times lags times draws) of the coefficients.
Ginv_large
is a three-dimensional array (K times K times draws) of the inverse of the G matrix.
A_large
is a three-dimensional array (K times K+1 times draws) of the posterior estimates for the K coefficients plus a global constant.
F.eigen
in case eigen="TRUE"
, returns a vector that contains for each posterior draw the modulus of the largest eigenvalue of the companion matrix.
trim.info
is a character vector. Contains information regarding the nr. of stable draws out of total (thinned) draws. Experience shows that a maximum eigenvalue of 1.05
seems a reasonable choice when working with data in levels to generate stable impulse responses.
cc.results
each entry of this list contains an list object of length N
. Each entry in the list corresponds to one country model and contains one of the following posterior medians.
coeffs
contains in each entry the matrix with the posterior median of the estimated coefficients. Columns of the matrix correspond to an equation in the country model (i.e., the dependent variable) and rows to coefficient estimates of the explanatory variables.
sig
contains in each entry the variance-covariance matrix for each point in time. If SV=FALSE
all entries along the time dimension are the same.
theta
contains in each entry the estimated prior variances for the coefficients. Explains how much shrinkage is induced on each coefficient depending on the prior setup.
res
contains in each entry a matrix of dimension (T-p times K) with the posterior median of the residuals of the cross-country models.
shrink
in case prior="MN"
each entry contains the estimated shrinkage parameters.
PIP
in case prior="SSVS"
returns a list object. The first slot in the list PIP.cc
, is a list of length N
and contains the posterior inclusion probabilities of the country models. The second slot in the list, named PIP.avg
yields simple averages (over the country models where a particular variable has been included) of the posterior inclusion probabilities.
lambda2
in case prior="NG"
each entry contains the estimated global shrinkage parameters. It is a matrix of dimension (p+1 times 3). Columns refer to the endogenous, weakly exogenous and shrinkage parameters for the covariances. Rows correspond to different degree of shrinkage per lag of the variables starting with the contemporaneous lag (only for weakly exogenous variables). In case of the covariances just one global shrinkage parameter is estimated.
tau
in case prior="NG"
each entry contains the estimated parameter that governs the heaviness of the tails of the marginal prior distribution of the coefficients associated to endogenous variables. Structure is the same as lambda2
.
We provide three priors, the Minnesota labeled MN
, the Stochastic Search Variable Selection prior labeled SSVS
and the Normal-Gamma prior labeled NG
. The first one has been implemented for global VARs in Feldkircher and Huber (2016) and the second one in Crespo Cuaresma et al. (2016), while the last one has been introduced to VAR modeling in Huber and Feldkircher (2019).
Please consult these references for more details on the specification. In the following we will briefly explain the difference between the three priors. The Minnesota prior pushes the variables in the country-specific VAR towards their unconditional stationary mean, or toward a situation where there is at least one unit root present. The SSVS prior is a form of a 'spike' and 'slab' prior. Variable selection is based on the probability of assigning the corresponding regression coefficient to the 'slab' component. If a regression coefficient is non informative, the 'spike' component pushes the associated posterior estimate more strongly towards zero. Otherwise, the slab component resembles a non-informative prior that has little impact on the posterior. Following George et. al. (2008) we set the prior variances for the normal distribution in a semi-automatic fashion. This implies scaling the mixture normal with the OLS standard errors of the coefficients for the full model. The NG prior is a form of global-local shrinkage prior. Hence, the local component shrinks each coefficient towards zero if there is no information for the associated dependent variable. Otherwise, the prior exerts a fat-tail structure such that deviations from zero are possible. The global component is present for each lag, thus capturing the idea that higher lags should be shrunk more aggressively towards zero.
Crespo Cuaresma, J., Feldkircher, M. and F. Huber (2016) Forecasting with Global Vector Autoregressive Models: A Bayesian Approach. Journal of Applied Econometrics, Vol. 31(7), pp. 1371-1391.
Doan, T. R., Litterman, B. R. and C. A. Sims (1984) Forecasting and Conditional Projection Using Realistic Prior Distributions. Econometric Reviews, Vol. 3, pp. 1-100.
Dovern, J., Feldkircher, M. and F. Huber (2016) Does joint modelling of the world economy pay off? Evaluating multivariate forecasts from a Bayesian GVAR. Journal of Economic Dynamics and Control, Vol. 70, pp. 86-100.
Feldkircher, M. and F. Huber (2016) The International Transmission of US Shocks - Evidence from Bayesian Global Vector Autoregressions. European Economic Review, Vol. 81, pp. 167-188.
Feldkircher, M. Gruber, T. and F. Huber (2020) International effects of a compression of euro area yield curves. Journal of Banking & Finance, Vol. 113, pp. 11-14.
George, E.I., Sun, D. and S. Ni (2008) Bayesian stochastic search for var model restrictions. Journal of Econometrics, Vol. 142, pp. 553-580.
Georgiadis, G. (2015) Examining asymmetries in the transmission of monetary policy in the euro area: Evidence from a mixed cross-section global VAR model. European Economic Review, Vol. 75, pp. 195-215.
Huber, F. and M. Feldkircher (2016) Adaptive Shrinkage in Bayesian Vector Autoregressive Models. Journal of Business and Economic Statistics, Vol. 37(1), pp. 27-39.
Mohaddes, K. and M. Raissi (2018). Compilation, Revision and Updating of the Global VAR (GVAR) Database, 1979Q2-2016Q4. University of Cambridge: Faculty of Economics (mimeo).
Mohaddes, K. and M. Raissi (2019) The US oil supply revolution and the global economy. Empirical Economics, Vol. 57, pp. 515-546.
Pesaran, M.H., Schuermann T. and S.M. Weiner (2004) Modeling Regional Interdependencies Using a Global Error-Correcting Macroeconometric Model. Journal of Business and Economic Statistics, Vol. 22, pp. 129-162.
Sims, C. A. (1992) Bayesian Inference for Multivariate Time Series with Trend. Mimeo, presented at the American statistical Association meeting.
Sims, C.A. and T. Zha (1998) Bayesian Methods for Dynamic Multivariate Models. International Economic Review, Vol. 39, pp. 949-968.
# NOT RUN {
library(BGVAR)
data(eerDatasmall)
hyperpara <- list(tau0=0.1,tau1=3,kappa0=0.1,kappa1=7,a_1=0.01,b_1=0.01,p_i=0.5,q_ij=0.5)
model.ssvs <- bgvar(Data=eerDatasmall,W=W.trade0012.small,plag=1,draws=100,burnin=100,
prior="SSVS",SV=FALSE,hyperpara=hyperpara,thin=1)
# }
# NOT RUN {
library(BGVAR)
# replicate Feldkircher and Huber (2016) using trade based weights
data(eerData)
hyperpara <- list(tau0=0.1,tau1=3,kappa0=0.1,kappa1=7,a_1=0.01,b_1=0.01,p_i=0.5,q_ij=0.5)
model.ssvs <- bgvar(Data=eerData,W=W.trade0012,plag=1,draws=100,burnin=100,
prior="SSVS",SV=FALSE,hyperpara=hyperpara,thin=1)
print(model.ssvs)
# use different weight matrices
variable.list<-list();variable.list$real<-c("y","Dp","tb");variable.list$fin<-c("stir","ltir","rer")
model.mn <- bgvar(Data=eerData, W=W.list[c("tradeW.0012","finW0711")], plag=1, draws=200,
burnin=100,prior="MN",SV=TRUE,thin=2,expert=list(variable.list=variable.list))
print(model.mn)
data(monthlyData)
EA.weights$variables <- c("EAstir","total.assets","M3","ciss","y","p")
OC.weights$variables <- c("poil","qoil","y")
OE.weights <- list(EB=EA.weights,OC=OC.weights)
hyperpara<-list(d_lambda = 0.01, e_lambda = 0.01,e_lambda=1.5,d_lambda=1,
prmean=0,a_1=0.01,b_1=0.01,tau_theta=.6,sample_tau=FALSE)
model.ssvs <- bgvar(Data=monthlyData,W=W,plag=2,draws=100,burnin=100,prior="SSVS",
hyperpara=hyperpara,eigen=TRUE,SV=TRUE,expert=list(OE.weights=OE.weights))
print(model.ssvs)
# }
Run the code above in your browser using DataLab