bayes_dsge_var: Bayesian VAR with DSGE-Implied Prior (DSGE-VAR)

View source: R/dsge-var.R

bayes_dsge_varR Documentation

Bayesian VAR with DSGE-Implied Prior (DSGE-VAR)

Description

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.

Usage

bayes_dsge_var(
  model,
  data,
  params = NULL,
  shock_sd = NULL,
  p = 4L,
  lambda = 1,
  n_draws = 1000L,
  include_intercept = TRUE,
  seed = NULL
)

Arguments

model

A dsge_solution or dsge_model object. If a model is supplied, params and shock_sd must also be given so the model can be solved.

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 model is a dsge_model.

shock_sd

Named numeric vector of shock standard deviations, used only when model is a dsge_model.

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 lambda * T observations. Default 1.0.

n_draws

Integer. Number of posterior draws to return. Default 1000.

include_intercept

Logical. Add a constant term to the VAR. Default TRUE.

seed

Optional integer seed for reproducibility.

Details

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).

Value

An object of class "dsge_dsgevar" with elements:

Phi_post

Array (k x n_y x n_draws) of posterior draws of the VAR coefficient matrix.

Sigma_post

Array (n_y x n_y x n_draws) of posterior draws of the innovation covariance matrix.

Phi_mean

Posterior mean of Phi.

Sigma_mean

Posterior mean of Sigma.

log_marg_lik

Approximate log marginal likelihood of the DSGE-VAR(lambda) model – useful for choosing the optimal lambda by maximisation.

lambda

The prior weight used.

p

The lag order.

T

Effective sample size used (rows of data minus p).

var_names

Observable / VAR variable names.

solution

The DSGE solution used to build the prior.

References

Del Negro, M. and Schorfheide, F. (2004). Priors from general equilibrium models for VARs. International Economic Review, 45(2), 643-673.

Examples


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)



dsge documentation built on Sept. 25, 2026, 5:08 p.m.