| bayes_dsge_var | R Documentation |
Estimates a Bayesian VAR whose prior on the autoregressive
coefficients and innovation covariance is centred on the second-moment
implications of a structural DSGE model. The scalar
lambda controls the tightness of the DSGE prior relative to the
sample data: lambda = 0 gives essentially an unrestricted
Bayesian VAR, while large lambda pulls the VAR toward DSGE
implied dynamics.
bayes_dsge_var(
model,
data,
params = NULL,
shock_sd = NULL,
p = 4L,
lambda = 1,
n_draws = 1000L,
include_intercept = TRUE,
seed = NULL
)
model |
A |
data |
Numeric matrix or data frame of observed variables (rows = time, columns = observables). Column names must match the model's observed-variable names. |
params |
Named numeric vector of structural parameters, used only
when |
shock_sd |
Named numeric vector of shock standard deviations,
used only when |
p |
Integer. VAR lag order. Default 4. |
lambda |
Numeric scalar (>= 0). Weight on the DSGE prior in
units of effective sample size; the prior is worth |
n_draws |
Integer. Number of posterior draws to return. Default 1000. |
include_intercept |
Logical. Add a constant term to the VAR.
Default |
seed |
Optional integer seed for reproducibility. |
The combined posterior moments are
\bar{M}_{XX} = X'X + \lambda T \Gamma_{XX}(\theta),\quad
\bar{M}_{XY} = X'Y + \lambda T \Gamma_{XY}(\theta),\quad
\bar{M}_{YY} = Y'Y + \lambda T \Gamma_{YY}(\theta)
where the DSGE-implied moment matrices are constructed from the
unconditional autocovariances \Gamma_{yy}(0), \ldots, \Gamma_{yy}(p).
The unconditional state covariance solves
\Sigma_x = H \Sigma_x H' + M M'; observable autocovariances are
\Gamma_{yy}(k) = Z H^{|k|} \Sigma_x Z' (with appropriate transpose
for negative lags).
The approximate log marginal likelihood follows the Del Negro– Schorfheide formula
\log p(Y \mid \lambda) = -\frac{T n_y}{2}\log\pi
+ \frac{n_y}{2}\log|\Gamma_{XX} \cdot \lambda T|
- \frac{n_y}{2}\log|\bar{M}_{XX}|
+ \frac{\lambda T}{2}\log|\lambda T\, \Gamma_{YY|X}|
- \frac{\bar{T}}{2}\log|\bar{S}|
+ \log\Gamma_{n_y}(\bar{T}/2) - \log\Gamma_{n_y}(\lambda T/2)
where \Gamma_{n_y} is the multivariate gamma function. This
value is useful for comparing different choices of lambda
(higher = better fit).
An object of class "dsge_dsgevar" with elements:
Phi_postArray (k x n_y x n_draws) of posterior draws of the VAR coefficient matrix.
Sigma_postArray (n_y x n_y x n_draws) of posterior draws of the innovation covariance matrix.
Phi_meanPosterior mean of Phi.
Sigma_meanPosterior mean of Sigma.
log_marg_likApproximate log marginal likelihood of
the DSGE-VAR(lambda) model – useful for choosing the optimal
lambda by maximisation.
lambdaThe prior weight used.
pThe lag order.
TEffective sample size used (rows of data minus p).
var_namesObservable / VAR variable names.
solutionThe DSGE solution used to build the prior.
Del Negro, M. and Schorfheide, F. (2004). Priors from general equilibrium models for VARs. International Economic Review, 45(2), 643-673.
nk <- dsge_model(
obs(p ~ beta * lead(p) + kappa * x),
unobs(x ~ lead(x) - (r - lead(p) - g)),
obs(r ~ psi * p + u),
state(u ~ rhou * u),
state(g ~ rhog * g),
fixed = list(beta = 0.99),
start = list(kappa = 0.1, psi = 1.5, rhou = 0.7, rhog = 0.9)
)
sol <- solve_dsge(nk,
params = c(kappa = 0.1, psi = 1.5, rhou = 0.7, rhog = 0.9),
shock_sd = c(e.u = 1.0, e.g = 0.5))
# Simulate data from the solution
set.seed(1)
TT <- 120
xst <- matrix(0, TT, nrow(sol$H))
y <- matrix(0, TT, nrow(sol$G))
for (t in 2:TT) {
e <- rnorm(ncol(sol$M)) * c(1, 0.5)
xst[t, ] <- as.numeric(sol$H %*% xst[t-1, ] + sol$M %*% e)
y[t, ] <- as.numeric(sol$G %*% xst[t, ])
}
colnames(y) <- rownames(sol$G)
dat <- as.data.frame(y[, nk$variables$observed, drop = FALSE])
fit <- bayes_dsge_var(sol, data = dat, p = 2, lambda = 1.0,
n_draws = 100, seed = 1)
print(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.