Title: | MCMC Estimation of Bayesian Vectorautoregressions |
---|---|
Description: | Efficient Markov Chain Monte Carlo (MCMC) algorithms for the fully Bayesian estimation of vectorautoregressions (VARs) featuring stochastic volatility (SV). Implements state-of-the-art shrinkage priors following Gruber & Kastner (2023) <doi:10.48550/arXiv.2206.04902>. Efficient equation-per-equation estimation following Kastner & Huber (2020) <doi:10.1002/for.2680> and Carrerio et al. (2021) <doi:10.1016/j.jeconom.2021.11.010>. |
Authors: | Luis Gruber [cph, aut, cre] , Gregor Kastner [ctb] |
Maintainer: | Luis Gruber <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.5 |
Built: | 2024-11-13 22:16:47 UTC |
Source: | https://github.com/luisgruber/bayesianvars |
Extract or replace parts of a bayesianVARs_coef
object.
## S3 method for class 'bayesianVARs_coef' x[i, j, ...]
## S3 method for class 'bayesianVARs_coef' x[i, j, ...]
x |
An object of type |
i |
indices |
j |
indices |
... |
further indices |
An object of type bayesianVARs_coef
.
# 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) # Extract coefficients, which are of class bayesianVARs_coef phi <- coef(mod) phi[1,1,1]
# 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) # Extract coefficients, which are of class bayesianVARs_coef phi <- coef(mod) phi[1,1,1]
Extract or replace parts of a bayesianVARs_draws
object.
## S3 method for class 'bayesianVARs_draws' x[i, j, ...]
## S3 method for class 'bayesianVARs_draws' x[i, j, ...]
x |
An object of type |
i |
indices |
j |
indices |
... |
further indices |
An object of type bayesianVARs_draws
.
# 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) # Extract coefficients, which are of class bayesianVARs_draws phi <- coef(mod) phi[1,1,1]
# 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) # Extract coefficients, which are of class bayesianVARs_draws phi <- coef(mod) phi[1,1,1]
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", quiet = FALSE, startvals = list(), expert = list() )
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", quiet = FALSE, startvals = list(), expert = list() )
data |
Data matrix (can be a time series object). Each of |
lags |
Integer indicating the order of the VAR, i.e. the number of lags of the dependent variables included as predictors. |
draws |
single integer indicating the number of draws after the burnin |
burnin |
single integer indicating the number of draws discarded as burnin |
thin |
single integer. Every |
prior_intercept |
Either |
prior_phi |
|
prior_sigma |
|
sv_keep |
String equal to |
quiet |
logical value indicating whether information about the progress
during sampling should be displayed during sampling (default is
|
startvals |
optional list with starting values. |
expert |
optional list with expert settings. |
The VAR(p) model is of the following form: , where
is a
-dimensional vector of dependent variables and
is the error term of the same dimension.
is a
-dimensional vector containing lagged/past
values of the dependent variables
for
and
is a constant term (intercept) of dimension
. The reduced-form coefficient matrix
is of
dimension
.
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
are assumed to follow a
-dimensional
multivariate normal distribution with zero mean and variance-covariance matrix
. In case of the
cholesky specification
, where
is upper unitriangular (with ones on
the diagonal). The diagonal matrix
depends upon latent
log-variances, i.e.
. The
log-variances follow a priori independent autoregressive processes
for
. In case of the factor structure,
. The diagonal matrices
and
depend upon latent log-variances, i.e.
and
. The log-variances
follow a priori independent autoregressive processes
for
and
for
.
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
: Numerical indicating the average time it took to generate one
single draw of the joint posterior distribution of all parameters.
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.
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. 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 , are sampled as in
Cogley and Sargent (2005).
Gruber, L. and Kastner, G. (2023). Forecasting macroeconomic data with Bayesian VARs: Sparse or dense? It depends! arXiv:2206.04902.
Kastner, G. and Huber, F. Sparse (2020). Bayesian vector autoregressions in huge dimensions. Journal of Forecasting. 39, 1142–1165, doi:10.1002/for.2680.
Kastner, G. (2019). Sparse Bayesian Time-Varying Covariance Estimation in Many Dimensions Journal of Econometrics, 210(1), 98–115, 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, 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, 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. 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)
# 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)
Extracts posterior draws of the VAR coefficients from a VAR
model estimated with bvar()
.
## S3 method for class 'bayesianVARs_bvar' coef(object, ...)
## S3 method for class 'bayesianVARs_bvar' coef(object, ...)
object |
A |
... |
Currently ignored. |
Returns a numeric array of dimension ,
where M is the number of time-series, K is the number of covariates per
equation (including the intercept) and draws is the number of stored
posterior draws.
summary.bayesianVARs_draws()
, vcov.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) # Extract posterior draws of VAR coefficients bvar_coefs <- coef(mod)
# 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) # Extract posterior draws of VAR coefficients bvar_coefs <- coef(mod)
Simulates the fitted/predicted (in-sample) values for an estimated VAR model.
## S3 method for class 'bayesianVARs_bvar' fitted(object, error_term = TRUE, ...)
## S3 method for class 'bayesianVARs_bvar' fitted(object, error_term = TRUE, ...)
object |
A |
error_term |
logical indicating whether to include the error term or not. |
... |
Currently ignored. |
An object of class bayesianVARs_fitted
.
# 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) # Simulate predicted historical values including the error term. pred <- fitted(mod, error_term = TRUE) # Simulate fitted historical values not including the error term. fit <- fitted(mod, error_term = FALSE) # Visualize plot(pred) plot(fit)
# 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) # Simulate predicted historical values including the error term. pred <- fitted(mod, error_term = TRUE) # Simulate fitted historical values not including the error term. fit <- fitted(mod, error_term = FALSE) # Visualize plot(pred) plot(fit)
Vectorized version of rgig
my_gig(n, lambda, chi, psi)
my_gig(n, lambda, chi, psi)
n |
A single integer indicating the number of draws to generate. |
lambda |
vector of shape parameters. |
chi |
vector of shape/scale parameters. Must be nonnegative for positive lambdas and positive else. |
psi |
vector of shape/scale parameters. Must be nonnegative for negative lambdas and positive else. |
Matrix of dimension c(n,m)
, where m
is the maximum length of lambda
, psi
and chi
.
gigsamples <- my_gig(2, c(1,1), c(1,1), c(1,1))
gigsamples <- my_gig(2, c(1,1), c(1,1), c(1,1))
Pairwise visualization of out-of-sample posterior predictive densities.
## S3 method for class 'bayesianVARs_predict' pairs(x, vars, ahead, ...)
## S3 method for class 'bayesianVARs_predict' pairs(x, vars, ahead, ...)
x |
An object of class |
vars |
Integer vector (or coercible to such) indicating which variables to plot. |
ahead |
Integer vector (or coercible to such) indicating which step
ahead to plot. |
... |
Currently ignored! |
Returns x
invisibly.
Note that that bayesianVARs_predict
can also be used withing plot.bayesianVARs_bvar()
.
Other plotting plot.bayesianVARs_bvar()
,
plot.bayesianVARs_fitted()
, plot.bayesianVARs_predict()
posterior_heatmap()
.
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize pairs(predictions, vars = 1:3, ahead = 1:3)
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize pairs(predictions, vars = 1:3, ahead = 1:3)
Visualization of in-sample fit. Can also be used to display prediction intervals of future values.
## S3 method for class 'bayesianVARs_bvar' plot( x, predictions = NULL, quantiles = c(0.05, 0.5, 0.95), dates = NULL, n_col = 1, ... )
## S3 method for class 'bayesianVARs_bvar' plot( x, predictions = NULL, quantiles = c(0.05, 0.5, 0.95), dates = NULL, n_col = 1, ... )
x |
An object of class |
predictions |
Optional array of out of sample predictions, e.g. obtained
via |
quantiles |
numeric vector indicating which quantiles to plot. |
dates |
optional vector of dates for labelling the x-axis. The default
values is |
n_col |
integer indicating the number of columns to use for plotting. |
... |
Currently ignored! |
Returns x
invisibly.
Other plotting plot.bayesianVARs_fitted()
,
plot.bayesianVARs_predict()
, pairs.bayesianVARs_predict()
,
posterior_heatmap()
.
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize plot(mod, predictions = predictions)
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize plot(mod, predictions = predictions)
Visualization of in-sample fit of an estimated VAR.
## S3 method for class 'bayesianVARs_fitted' plot( x, dates = NULL, vars = "all", quantiles = c(0.05, 0.5, 0.95), n_col = 1L, ... )
## S3 method for class 'bayesianVARs_fitted' plot( x, dates = NULL, vars = "all", quantiles = c(0.05, 0.5, 0.95), n_col = 1L, ... )
x |
A |
dates |
optional vector of dates for labelling the x-axis. The default
values is |
vars |
character vector containing the names of the variables to be
visualized. The default is |
quantiles |
numeric vector indicating which quantiles to plot. |
n_col |
integer indicating the number of columns to use for plotting. |
... |
Currently ignored. |
returns x
invisibly
fitted method for class 'bayesianVARs_bvar': fitted.bayesianVARs_bvar()
.
Other plotting plot.bayesianVARs_bvar()
,
plot.bayesianVARs_fitted()
, plot.bayesianVARs_predict()
,
pairs.bayesianVARs_predict()
, posterior_heatmap()
.
# 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) # Simulate predicted historical values including the error term. pred <- fitted(mod, error_term = TRUE) # Visualize plot(pred)
# 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) # Simulate predicted historical values including the error term. pred <- fitted(mod, error_term = TRUE) # Visualize plot(pred)
Visualization of (out-of-sample) predictive distribution.
## S3 method for class 'bayesianVARs_predict' plot( x, dates = NULL, vars = "all", ahead = NULL, quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95), n_col = 1L, first_obs = 1L, ... )
## S3 method for class 'bayesianVARs_predict' plot( x, dates = NULL, vars = "all", ahead = NULL, quantiles = c(0.05, 0.25, 0.5, 0.75, 0.95), n_col = 1L, first_obs = 1L, ... )
x |
An object of type |
dates |
optional vector of dates for labeling the x-axis. The default
values is |
vars |
character vector containing the names of the variables to be
visualized. The default is |
ahead |
Integer vector (or coercible to such) indicating which step
ahead to plot. |
quantiles |
numeric vector indicating which quantiles to plot. |
n_col |
integer indicating the number of columns to use for plotting. |
first_obs |
integer indicating the first observation to be used for plotting. |
... |
Currently ignored! |
Returns x
invisibly!
Other plotting plot.bayesianVARs_bvar()
,
plot.bayesianVARs_fitted()
, pairs.bayesianVARs_predict()
posterior_heatmap()
.
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize plot(predictions, vars = 1:3, ahead = 1:3)
# 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) # Simulate from posterior predictive predictions <- predict(mod, ahead = 1:3) # Visualize plot(predictions, vars = 1:3, ahead = 1:3)
Posterior heatmaps for VAR coefficients or variance-covariance matrices
posterior_heatmap( x, FUN, ..., colorbar = TRUE, xlabels = NULL, ylabels = NULL, add_numbers = FALSE, zlim = NULL, colspace = NULL, main = "", cex.axis = 0.75, cex.colbar = 1, cex.numbers = 1, asp = NULL )
posterior_heatmap( x, FUN, ..., colorbar = TRUE, xlabels = NULL, ylabels = NULL, add_numbers = FALSE, zlim = NULL, colspace = NULL, main = "", cex.axis = 0.75, cex.colbar = 1, cex.numbers = 1, asp = NULL )
x |
An array of dimension |
FUN |
The summary function to be applied to margins |
... |
optional arguments to |
colorbar |
logical indicating whether to display a colorbar or not.
Default is |
xlabels |
|
ylabels |
|
add_numbers |
logical. |
zlim |
numeric vector of length two indicating the minimum and maximum values for which colors should be plotted. By default this range is determined by the maximum of the absolute values of the selected summary. |
colspace |
Optional argument. |
main |
main title for the plot. |
cex.axis |
The magnification to be used for y-axis annotation relative to the current setting of cex. |
cex.colbar |
The magnification to be used for colorbar annotation relative to the current setting of cex. |
cex.numbers |
The magnification to be used for the actual values (if
|
asp |
aspect ratio. |
Returns x
invisibly.
Other plotting plot.bayesianVARs_bvar()
,
plot.bayesianVARs_fitted()
, plot.bayesianVARs_predict()
,
pairs.bayesianVARs_predict()
.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate a model mod <- bvar(100*data, sv_keep = "all", quiet = TRUE) # Extract posterior draws of VAR coefficients phi_post <- coef(mod) # Visualize posterior median of VAR coefficients posterior_heatmap(phi_post, median) # Extract posterior draws of variance-covariance matrices (for each point in time) sigma_post <- vcov(mod) # Visualize posterior interquartile-range of variance-covariance matrix of the first observation posterior_heatmap(sigma_post[1,,,], IQR)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate a model mod <- bvar(100*data, sv_keep = "all", quiet = TRUE) # Extract posterior draws of VAR coefficients phi_post <- coef(mod) # Visualize posterior median of VAR coefficients posterior_heatmap(phi_post, median) # Extract posterior draws of variance-covariance matrices (for each point in time) sigma_post <- vcov(mod) # Visualize posterior interquartile-range of variance-covariance matrix of the first observation posterior_heatmap(sigma_post[1,,,], IQR)
Simulates from (out-of-sample) predictive density for Bayesian VARs estimated
via bvar()
and computes log predictive likelhoods if ex-post
observed data is supplied.
## S3 method for class 'bayesianVARs_bvar' predict( object, ahead = 1L, each = 1L, stable = TRUE, simulate_predictive = TRUE, LPL = FALSE, Y_obs = NA, LPL_VoI = NA, ... )
## S3 method for class 'bayesianVARs_bvar' predict( object, ahead = 1L, each = 1L, stable = TRUE, simulate_predictive = TRUE, LPL = FALSE, Y_obs = NA, LPL_VoI = NA, ... )
object |
A |
ahead |
Integer vector (or coercible to such), indicating the number of steps ahead at which to predict. |
each |
Single integer (or coercible to such) indicating how often should be drawn from the posterior predictive distribution for each draw that has been stored during MCMC sampling. |
stable |
logical indicating whether to consider only those draws from
the posterior that fulfill the 'stable' criterion. Default is |
simulate_predictive |
logical, indicating whether the posterior predictive distribution should be simulated. |
LPL |
logical indicating whether |
Y_obs |
Data matrix of observed values for computation of log predictive
likelihood. Each of |
LPL_VoI |
either integer vector or character vector of column-names
indicating for which subgroup of time-series in |
... |
Currently ignored! |
Object of class bayesianVARs_predict
, a list that may contain the
following elements:
predictions
array of dimensions
c(length(ahead), ncol(object$Yraw), each * dim(object$PHI)[3])
containing the simulations from the predictive density (if
simulate_predictive=TRUE
).
LPL
vector of length length(ahead)
containing the
log-predictive-likelihoods (taking into account the joint distribution of
all variables) (if LPL=TRUE
).
LPL_univariate
matrix of dimension c(length(ahead), ncol(object$Yraw)
containing the marginalized univariate log-predictive-likelihoods of each
series (if LPL=TRUE
).
LPL_VoI
vector of length length(ahead)
containing the
log-predictive-likelihoods for a subset of variables (if LPL=TRUE
and
LPL_VoI != NA
).
Yraw
matrix containing the data used for the estimation of the VAR.
LPL_draws
matrix containing the simulations of the
log-predictive-likelihood (if LPL=TRUE
).
PL_univariate_draws
array containing the simulations of the univariate
predictive-likelihoods (if LPL=TRUE
).
LPL_sub_draws
matrix containing the simulations of the
log-predictive-likelihood for a subset of variables (if LPL=TRUE
and
LPL_VoI != NA
).
stable_bvar()
, plot.bayesianVARs_predict()
, pairs.bayesianVARs_predict()
.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step to 4-steps ahead posterior predictive and compute # log-predictive-likelihoods predictions <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test) # Summary summary(predictions) # Visualize via fan-charts plot(predictions) # In order to evaluate the joint predictive density of a subset of the # variables (variables of interest), consider specifying 'LPL_VoI': predictions <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test, LPL_VoI = c("GDPC1","FEDFUNDS")) predictions$LPL_VoI
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step to 4-steps ahead posterior predictive and compute # log-predictive-likelihoods predictions <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test) # Summary summary(predictions) # Visualize via fan-charts plot(predictions) # In order to evaluate the joint predictive density of a subset of the # variables (variables of interest), consider specifying 'LPL_VoI': predictions <- predict(mod, ahead = 1:4, LPL = TRUE, Y_obs = test, LPL_VoI = c("GDPC1","FEDFUNDS")) predictions$LPL_VoI
Pretty printing of a bvar object
## S3 method for class 'bayesianVARs_bvar' print(x, ...)
## S3 method for class 'bayesianVARs_bvar' print(x, ...)
x |
Object of class |
... |
Ignored. |
Returns x
invisibly.
# 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) # Print model mod
# 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) # Print model mod
Print method for bayesianVARs_predict objects.
## S3 method for class 'bayesianVARs_predict' print(x, ...)
## S3 method for class 'bayesianVARs_predict' print(x, ...)
x |
A |
... |
Currently ignored! |
Returns x
invisibly.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) print(predictions)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) print(predictions)
Print method for summary.bayesianVARs_bvar
objects.
## S3 method for class 'summary.bayesianVARs_bvar' print(x, ...)
## S3 method for class 'summary.bayesianVARs_bvar' print(x, ...)
x |
A |
... |
Currently ignored! |
Returns x
invisibly!
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate model mod <- bvar(data, quiet = TRUE) # Print summary summary(mod)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate model mod <- bvar(data, quiet = TRUE) # Print summary summary(mod)
Print method for summary.bayesianVARs_predict
objects.
## S3 method for class 'summary.bayesianVARs_predict' print(x, ...)
## S3 method for class 'summary.bayesianVARs_predict' print(x, ...)
x |
A |
... |
Currently ignored. |
Returns x
invisibly.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) sum <- summary(predictions) print(sum)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) sum <- summary(predictions) print(sum)
Configures prior on PHI, the matrix of reduced-form VAR coefficients.
specify_prior_phi( data = NULL, M = ncol(data), lags = 1L, prior = "HS", priormean = 0, PHI_tol = 1e-18, DL_a = "1/K", DL_tol = 0, R2D2_a = 0.1, R2D2_b = 0.5, R2D2_tol = 0, NG_a = 0.1, NG_b = 1, NG_c = 1, NG_tol = 0, SSVS_c0 = 0.01, SSVS_c1 = 100, SSVS_semiautomatic = TRUE, SSVS_p = 0.5, HMP_lambda1 = c(0.01, 0.01), HMP_lambda2 = c(0.01, 0.01), normal_sds = 10, global_grouping = "global", ... )
specify_prior_phi( data = NULL, M = ncol(data), lags = 1L, prior = "HS", priormean = 0, PHI_tol = 1e-18, DL_a = "1/K", DL_tol = 0, R2D2_a = 0.1, R2D2_b = 0.5, R2D2_tol = 0, NG_a = 0.1, NG_b = 1, NG_c = 1, NG_tol = 0, SSVS_c0 = 0.01, SSVS_c1 = 100, SSVS_semiautomatic = TRUE, SSVS_p = 0.5, HMP_lambda1 = c(0.01, 0.01), HMP_lambda2 = c(0.01, 0.01), normal_sds = 10, global_grouping = "global", ... )
data |
Optional. Data matrix (can be a time series object). Each of
|
M |
positive integer indicating the number of time-series of the VAR. |
lags |
positive integer indicating the order of the VAR, i.e. the number of lags of the dependent variables included as predictors. |
prior |
character, one of |
priormean |
real numbers indicating the prior means of the VAR
coefficients. One single number means that the prior mean of all own-lag
coefficients w.r.t. the first lag equals |
PHI_tol |
Minimum number that the absolute value of a VAR coefficient draw can take. Prevents numerical issues that can appear when strong shrinkage is enforced if chosen to be greater than zero. |
DL_a |
(Single) positive real number. The value is interpreted as the
concentration parameter for the local scales. Smaller values enforce heavier
shrinkage. If the argument |
DL_tol |
Minimum number that a parameter draw of one of the shrinking
parameters of the Dirichlet Laplace prior can take. Prevents numerical
issues that can appear when strong shrinkage is enforced if chosen to be
greater than zero. |
R2D2_a |
(Single) positive real number. The value is interpreted as the
concentration parameter for the local scales. Smaller values enforce heavier
shrinkage. If the argument |
R2D2_b |
(Single) positive real number. The value indicates the shape
parameter of the inverse gamma prior on the (semi-)global scales. If the
argument |
R2D2_tol |
Minimum number that a parameter draw of one of the shrinking
parameters of the R2D2 prior can take. Prevents numerical issues that can
appear when strong shrinkage is enforced if chosen to be greater than zero.
|
NG_a |
(Single) positive real number. The value is interpreted as the
concentration parameter for the local scales. Smaller values enforce heavier
shrinkage. If the argument |
NG_b |
(Single) positive real number. The value indicates the shape
parameter of the inverse gamma prior on the (semi-)global scales. If the
argument |
NG_c |
(Single) positive real number. The value indicates the scale
parameter of the inverse gamma prior on the (semi-)global scales. If the
argument |
NG_tol |
Minimum number that a parameter draw of one of the shrinking
parameters of the normal-gamma prior can take. Prevents numerical issues
that can appear when strong shrinkage is enforced if chosen to be greater
than zero. |
SSVS_c0 |
single positive number indicating the (unscaled) standard
deviation of the spike component. |
SSVS_c1 |
single positive number indicating the (unscaled) standard
deviation of the slab component. |
SSVS_semiautomatic |
logical. If |
SSVS_p |
Either a single positive number in the range |
HMP_lambda1 |
numeric vector of length 2. Both entries must be positive.
The first indicates the shape and the second the rate of the Gamma
hyperprior on own-lag coefficients. |
HMP_lambda2 |
numeric vector of length 2. Both entries must be positive.
The first indicates the shape and the second the rate of the Gamma
hyperprior on cross-lag coefficients. |
normal_sds |
numeric vector of length |
global_grouping |
One of |
... |
Do not use! |
For details concerning prior-elicitation for VARs please see Gruber & Kastner (2023).
Currently one can choose between six hierarchical shrinkage priors and a
normal prior: prior="HS"
stands for the Horseshoe-prior, prior="R2D2
for
the R-induced-Dirichlet-decompostion-prior,
prior="NG"
for the
normal-gamma-prior, prior="DL"
for the Dirichlet-Laplace-prior,
prior="SSVS"
for the stochastic-search-variable-selection-prior,
prior="HMP"
for the semi-hierarchical Minnesota prior and prior=normal
for
the normal-prior.
Semi-global shrinkage, i.e. group-specific shrinkage for pre-specified
subgroups of the coefficients, can be achieved through the argument
global_grouping
.
A baysianVARs_prior_phi
-object.
Gruber, L. and Kastner, G. (2023). Forecasting macroeconomic data with Bayesian VARs: Sparse or dense? It depends! arXiv:2206.04902.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Horseshoe prior for a VAR(2) phi_hs <- specify_prior_phi(data = data, lags = 2L ,prior = "HS") # Semi-global-local Horseshoe prior for a VAR(2) with semi-global shrinkage parameters for # cross-lag and own-lag coefficients in each lag phi_hs_sg <- specify_prior_phi(data = data, lags = 2L, prior = "HS", global_grouping = "olcl-lagwise") # Semi-global-local Horseshoe prior for a VAR(2) with equation-wise shrinkage # construct indicator matrix for equation-wise shrinkage semi_global_mat <- matrix(1:ncol(data), 2*ncol(data), ncol(data), byrow = TRUE) phi_hs_ew <- specify_prior_phi(data = data, lags = 2L, prior = "HS", global_grouping = semi_global_mat) # (for equation-wise shrinkage one can also use 'global_grouping = "equation-wise"') # Estimate model with your prior configuration of choice mod <- bvar(data, lags = 2L, prior_phi = phi_hs_sg, quiet = TRUE)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Horseshoe prior for a VAR(2) phi_hs <- specify_prior_phi(data = data, lags = 2L ,prior = "HS") # Semi-global-local Horseshoe prior for a VAR(2) with semi-global shrinkage parameters for # cross-lag and own-lag coefficients in each lag phi_hs_sg <- specify_prior_phi(data = data, lags = 2L, prior = "HS", global_grouping = "olcl-lagwise") # Semi-global-local Horseshoe prior for a VAR(2) with equation-wise shrinkage # construct indicator matrix for equation-wise shrinkage semi_global_mat <- matrix(1:ncol(data), 2*ncol(data), ncol(data), byrow = TRUE) phi_hs_ew <- specify_prior_phi(data = data, lags = 2L, prior = "HS", global_grouping = semi_global_mat) # (for equation-wise shrinkage one can also use 'global_grouping = "equation-wise"') # Estimate model with your prior configuration of choice mod <- bvar(data, lags = 2L, prior_phi = phi_hs_sg, quiet = TRUE)
Configures prior on the variance-covariance of the VAR.
specify_prior_sigma( data = NULL, M = ncol(data), type = c("factor", "cholesky"), factor_factors = 1L, factor_restrict = c("none", "upper"), factor_priorfacloadtype = c("rowwiseng", "colwiseng", "normal"), factor_priorfacload = 0.1, factor_facloadtol = 1e-18, factor_priorng = c(1, 1), factor_priormu = c(0, 10), factor_priorphiidi = c(10, 3), factor_priorphifac = c(10, 3), factor_priorsigmaidi = 1, factor_priorsigmafac = 1, factor_priorh0idi = "stationary", factor_priorh0fac = "stationary", factor_heteroskedastic = TRUE, factor_priorhomoskedastic = NA, factor_interweaving = 4, cholesky_U_prior = c("HS", "DL", "R2D2", "NG", "SSVS", "normal", "HMP"), cholesky_U_tol = 1e-18, cholesky_heteroscedastic = TRUE, cholesky_priormu = c(0, 100), cholesky_priorphi = c(20, 1.5), cholesky_priorsigma2 = c(0.5, 0.5), cholesky_priorh0 = "stationary", cholesky_priorhomoscedastic = as.numeric(NA), cholesky_DL_a = "1/n", cholesky_DL_tol = 0, cholesky_R2D2_a = 0.4, cholesky_R2D2_b = 0.5, cholesky_R2D2_tol = 0, cholesky_NG_a = 0.5, cholesky_NG_b = 0.5, cholesky_NG_c = 0.5, cholesky_NG_tol = 0, cholesky_SSVS_c0 = 0.001, cholesky_SSVS_c1 = 1, cholesky_SSVS_p = 0.5, cholesky_HMP_lambda3 = c(0.01, 0.01), cholesky_normal_sds = 10, expert_sv_offset = 0, quiet = FALSE, ... )
specify_prior_sigma( data = NULL, M = ncol(data), type = c("factor", "cholesky"), factor_factors = 1L, factor_restrict = c("none", "upper"), factor_priorfacloadtype = c("rowwiseng", "colwiseng", "normal"), factor_priorfacload = 0.1, factor_facloadtol = 1e-18, factor_priorng = c(1, 1), factor_priormu = c(0, 10), factor_priorphiidi = c(10, 3), factor_priorphifac = c(10, 3), factor_priorsigmaidi = 1, factor_priorsigmafac = 1, factor_priorh0idi = "stationary", factor_priorh0fac = "stationary", factor_heteroskedastic = TRUE, factor_priorhomoskedastic = NA, factor_interweaving = 4, cholesky_U_prior = c("HS", "DL", "R2D2", "NG", "SSVS", "normal", "HMP"), cholesky_U_tol = 1e-18, cholesky_heteroscedastic = TRUE, cholesky_priormu = c(0, 100), cholesky_priorphi = c(20, 1.5), cholesky_priorsigma2 = c(0.5, 0.5), cholesky_priorh0 = "stationary", cholesky_priorhomoscedastic = as.numeric(NA), cholesky_DL_a = "1/n", cholesky_DL_tol = 0, cholesky_R2D2_a = 0.4, cholesky_R2D2_b = 0.5, cholesky_R2D2_tol = 0, cholesky_NG_a = 0.5, cholesky_NG_b = 0.5, cholesky_NG_c = 0.5, cholesky_NG_tol = 0, cholesky_SSVS_c0 = 0.001, cholesky_SSVS_c1 = 1, cholesky_SSVS_p = 0.5, cholesky_HMP_lambda3 = c(0.01, 0.01), cholesky_normal_sds = 10, expert_sv_offset = 0, quiet = FALSE, ... )
data |
Optional. Data matrix (can be a time series object). Each of
|
M |
positive integer indicating the number of time-series of the VAR. |
type |
character, one of |
factor_factors |
Number of latent factors to be estimated. Only required
if |
factor_restrict |
Either "upper" or "none", indicating whether the factor
loadings matrix should be restricted to have zeros above the diagonal
("upper") or whether all elements should be estimated from the data
("none"). Setting |
factor_priorfacloadtype |
Can be
For details please see Kastner (2019). |
factor_priorfacload |
Either a matrix of dimensions |
factor_facloadtol |
Minimum number that the absolute value of a factor
loadings draw can take. Prevents numerical issues that can appear when
strong shrinkage is enforced if chosen to be greater than zero. Only
required if |
factor_priorng |
Two-element vector with positive entries indicating the
Normal-Gamma prior's hyperhyperparameters |
factor_priormu |
Vector of length 2 denoting prior mean and standard
deviation for unconditional levels of the idiosyncratic log variance
processes. Only required if |
factor_priorphiidi |
Vector of length 2, indicating the shape parameters
for the Beta prior distributions of the transformed parameters
|
factor_priorphifac |
Vector of length 2, indicating the shape parameters
for the Beta prior distributions of the transformed parameters
|
factor_priorsigmaidi |
Vector of length |
factor_priorsigmafac |
Vector of length |
factor_priorh0idi |
Vector of length 1 or |
factor_priorh0fac |
Vector of length 1 or |
factor_heteroskedastic |
Vector of length 1, 2, or |
factor_priorhomoskedastic |
Only used if at least one element of
|
factor_interweaving |
The following values for interweaving the factor
loadings are accepted (Only required if
For details please see Kastner et al. (2017). A value of 4 is the highly recommended default. |
cholesky_U_prior |
character, one of |
cholesky_U_tol |
Minimum number that the absolute value of an free
off-diagonal element of an |
cholesky_heteroscedastic |
single logical indicating whether time-varying
( |
cholesky_priormu |
Vector of length 2 denoting prior mean and standard
deviation for unconditional levels of the log variance processes. Only
required if |
cholesky_priorphi |
Vector of length 2, indicating the shape parameters
for the Beta prior distributions of the transformed parameters
|
cholesky_priorsigma2 |
Vector of length 2, indicating the shape and the
rate for the Gamma prior distributions on the variance of the log variance
processes. (Currently only one global setting for all |
cholesky_priorh0 |
Vector of length 1 or |
cholesky_priorhomoscedastic |
Only used if
|
cholesky_DL_a |
(Single) positive real number. The value is interpreted
as the concentration parameter for the local scales. Smaller values enforce
heavier shrinkage. A matrix of dimension |
cholesky_DL_tol |
Minimum number that a parameter draw of one of the
shrinking parameters of the Dirichlet Laplace prior can take. Prevents
numerical issues that can appear when strong shrinkage is enforced if chosen
to be greater than zero. |
cholesky_R2D2_a |
(Single) positive real number. The value is interpreted
as the concentration parameter for the local scales. Smaller values enforce
heavier shrinkage. A matrix of dimension |
cholesky_R2D2_b |
single positive number, where greater values indicate
heavier regularization. |
cholesky_R2D2_tol |
Minimum number that a parameter draw of one of the
shrinking parameters of the R2D2 prior can take. Prevents numerical issues
that can appear when strong shrinkage is enforced if chosen to be greater
than zero. |
cholesky_NG_a |
(Single) positive real number. The value is interpreted
as the concentration parameter for the local scales. Smaller values enforce
heavier shrinkage. A matrix of dimension |
cholesky_NG_b |
(Single) positive real number. The value indicates the
shape parameter of the inverse gamma prior on the global scales.
|
cholesky_NG_c |
(Single) positive real number. The value indicates the
scale parameter of the inverse gamma prior on the global scales.
Expert option would be to set the scale parameter proportional to NG_a. E.g.
in the case where a discrete hyperprior for NG_a is chosen, a desired
proportion of let's say 0.2 is achieved by setting NG_c="0.2a" (character
input!). |
cholesky_NG_tol |
Minimum number that a parameter draw of one of the
shrinking parameters of the normal-gamma prior can take. Prevents numerical
issues that can appear when strong shrinkage is enforced if chosen to be
greater than zero. |
cholesky_SSVS_c0 |
single positive number indicating the (unscaled)
standard deviation of the spike component. |
cholesky_SSVS_c1 |
single positive number indicating the (unscaled)
standard deviation of the slab component. |
cholesky_SSVS_p |
Either a single positive number in the range |
cholesky_HMP_lambda3 |
numeric vector of length 2. Both entries must be
positive. The first indicates the shape and the second the rate of the Gamma
hyperprior on the contemporaneous coefficients. |
cholesky_normal_sds |
numeric vector of length |
expert_sv_offset |
... Do not use! |
quiet |
logical indicating whether informative output should be omitted. |
... |
Do not use! |
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
are assumed to follow a
-dimensional
multivariate normal distribution with zero mean and variance-covariance matrix
. In case of the cholesky specification
, where
is upper unitriangular (with ones on
the diagonal). The diagonal matrix
depends upon latent
log-variances, i.e.
. The
log-variances follow a priori independent autoregressive processes
for
. In case of the factor structure,
. The diagonal matrices
and
depend upon latent log-variances, i.e.
and
. The log-variances
follow a priori independent autoregressive processes
for
and
for
.
Object of class bayesianVARs_prior_sigma
.
Kastner, G. (2019). Sparse Bayesian Time-Varying Covariance Estimation in Many Dimensions Journal of Econometrics, 210(1), 98–115, doi:10.1016/j.jeconom.2018.11.007
Kastner, G., Frühwirth-Schnatter, S., and Lopes, H.F. (2017). Efficient Bayesian Inference for Multivariate Factor Stochastic Volatility Models. Journal of Computational and Graphical Statistics, 26(4), 905–917, doi:10.1080/10618600.2017.1322091.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # examples with stochastic volatility (heteroscedasticity) ----------------- # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings sigma_factor_cng_sv <- specify_prior_sigma(data = data, type = "factor", factor_factors = 2L, factor_priorfacloadtype = "colwiseng", factor_heteroskedastic = TRUE) # cholesky-decomposition with Dirichlet-Laplace prior on U sigma_cholesky_dl_sv <- specify_prior_sigma(data = data, type = "cholesky", cholesky_U_prior = "DL", cholesky_DL_a = 0.5, cholesky_heteroscedastic = TRUE) # examples without stochastic volatility (homoscedasticity) ---------------- # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings sigma_factor_cng <- specify_prior_sigma(data = data, type = "factor", factor_factors = 2L, factor_priorfacloadtype = "colwiseng", factor_heteroskedastic = FALSE, factor_priorhomoskedastic = matrix(c(0.5,0.5), ncol(data), 2)) # cholesky-decomposition with Horseshoe prior on U sigma_cholesky_dl <- specify_prior_sigma(data = data, type = "cholesky", cholesky_U_prior = "HS", cholesky_heteroscedastic = FALSE) # Estimate model with your prior configuration of choice mod <- bvar(data, prior_sigma = sigma_factor_cng_sv, quiet = TRUE)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # examples with stochastic volatility (heteroscedasticity) ----------------- # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings sigma_factor_cng_sv <- specify_prior_sigma(data = data, type = "factor", factor_factors = 2L, factor_priorfacloadtype = "colwiseng", factor_heteroskedastic = TRUE) # cholesky-decomposition with Dirichlet-Laplace prior on U sigma_cholesky_dl_sv <- specify_prior_sigma(data = data, type = "cholesky", cholesky_U_prior = "DL", cholesky_DL_a = 0.5, cholesky_heteroscedastic = TRUE) # examples without stochastic volatility (homoscedasticity) ---------------- # factor-decomposition with 2 factors and colwise normal-gamma prior on the loadings sigma_factor_cng <- specify_prior_sigma(data = data, type = "factor", factor_factors = 2L, factor_priorfacloadtype = "colwiseng", factor_heteroskedastic = FALSE, factor_priorhomoskedastic = matrix(c(0.5,0.5), ncol(data), 2)) # cholesky-decomposition with Horseshoe prior on U sigma_cholesky_dl <- specify_prior_sigma(data = data, type = "cholesky", cholesky_U_prior = "HS", cholesky_heteroscedastic = FALSE) # Estimate model with your prior configuration of choice mod <- bvar(data, prior_sigma = sigma_factor_cng_sv, quiet = TRUE)
stable_bvar()
detects and discards all posterior draws of an
bayesianVARs_bvar
object that do not fulfill the stability condition:
A VAR(p) model is considered as stable only if the eigenvalues of the
companion form matrix lie inside the unit circle.
stable_bvar(object, quiet = FALSE)
stable_bvar(object, quiet = FALSE)
object |
A |
quiet |
logical indicating whether informative output should be omitted. |
An object of type 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) # Discard "unstable" draws stable_mod <- stable_bvar(mod)
# 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) # Discard "unstable" draws stable_mod <- stable_bvar(mod)
Summary method for bayesianVARs_bvar
objects.
## S3 method for class 'bayesianVARs_bvar' summary(object, quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975), ...)
## S3 method for class 'bayesianVARs_bvar' summary(object, quantiles = c(0.025, 0.25, 0.5, 0.75, 0.975), ...)
object |
A |
quantiles |
numeric vector which quantiles to compute. |
... |
Currently ignored! |
An object of type summary.bayesianVARs_bvar
.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate model mod <- bvar(data, quiet = TRUE) # Summary sum <- summary(mod)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Estimate model mod <- bvar(data, quiet = TRUE) # Summary sum <- summary(mod)
Summary statistics for bayesianVARs posterior draws.
## S3 method for class 'bayesianVARs_draws' summary(object, quantiles = c(0.25, 0.5, 0.75), ...)
## S3 method for class 'bayesianVARs_draws' summary(object, quantiles = c(0.25, 0.5, 0.75), ...)
object |
An object of class |
quantiles |
A vector of quantiles to evaluate. |
... |
Currently ignored. |
A list object of class bayesianVARs_draws_summary
holding
mean
: Vector or matrix containing the posterior mean.
sd
: Vector or matrix containing the posterior standard deviation .
quantiles
: Array containing the posterior quantiles.
Available extractors: coef.bayesianVARs_bvar()
,
vcov.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) # Extract posterior draws of VAR coefficients bvar_coefs <- coef(mod) # Compute summary statistics summary_stats <- summary(bvar_coefs) # Compute summary statistics of VAR coefficients without using coef() summary_stats <- summary(mod$PHI) # Test which list elements of 'mod' are of class 'bayesianVARs_draws'. names(mod)[sapply(names(mod), function(x) inherits(mod[[x]], "bayesianVARs_draws"))]
# 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) # Extract posterior draws of VAR coefficients bvar_coefs <- coef(mod) # Compute summary statistics summary_stats <- summary(bvar_coefs) # Compute summary statistics of VAR coefficients without using coef() summary_stats <- summary(mod$PHI) # Test which list elements of 'mod' are of class 'bayesianVARs_draws'. names(mod)[sapply(names(mod), function(x) inherits(mod[[x]], "bayesianVARs_draws"))]
Summary method for bayesianVARs_predict
objects.
## S3 method for class 'bayesianVARs_predict' summary(object, ...)
## S3 method for class 'bayesianVARs_predict' summary(object, ...)
object |
A |
... |
Currently ignored! |
A summary.bayesianVARs_predict
object.
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) summary(predictions)
# Access a subset of the usmacro_growth dataset data <- usmacro_growth[,c("GDPC1", "CPIAUCSL", "FEDFUNDS")] # Split data in train and test train <- data[1:(nrow(data)-4),] test <- data[-c(1:(nrow(data)-4)),] # Estimate model using train data only mod <- bvar(train, quiet = TRUE) # Simulate from 1-step ahead posterior predictive predictions <- predict(mod, ahead = 1L) summary(predictions)
21 selected quarterly time-series from 1953:Q1 to 2021:Q2. From FRED-QD data base (McCracken and Ng, 2021). Release date 2021-07. Data is transformed to be interpreted as growth-rates (first log-differences with the exception of interest rates, which are already growth rates).
usmacro_growth
usmacro_growth
A matrix with 247 rows and 21 columns.
Raw (untransformed) data available at https://www.stlouisfed.org/research/economists/mccracken/fred-databases, https://files.stlouisfed.org/files/htdocs/fred-md/quarterly/2021-07.csv.
McCracken, M. W. and Ng, S. (2021). FRED-QD: A Quarterly Database for Macroeconomic Research, Review, Federal Reserve Bank of St. Louis, 103(1), 1–44, doi:10.20955/r.103.1-44.
Returns the posterior draws of the possibly time-varying variance-covariance
matrix of a VAR estimated via bvar()
. Returns the full paths if
sv_keep="all"
when calling bvar()
. Otherwise, the draws of the
variance-covariance matrix for the last observation are returned, only.
## S3 method for class 'bayesianVARs_bvar' vcov(object, t = seq_len(nrow(object$logvar)), ...)
## S3 method for class 'bayesianVARs_bvar' vcov(object, t = seq_len(nrow(object$logvar)), ...)
object |
An object of class |
t |
Vector indicating which points in time should be extracted, defaults to all. |
... |
Currently ignored. |
An array of class bayesianVARs_draws
of dimension , where
is the number of observations,
the number of time-series and
the number of stored
posterior draws.
summary.bayesianVARs_draws
, coef.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) # Extract posterior draws of the variance-covariance matrix bvar_vcov <- vcov(mod)
# 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) # Extract posterior draws of the variance-covariance matrix bvar_vcov <- vcov(mod)