View source: R/bayes-estimate.R
| bayes_dsge | R Documentation |
Estimates the parameters of a DSGE model using Random-Walk Metropolis-Hastings (RWMH) with adaptive proposal covariance. Supports both linear models (dsge_model) and nonlinear models (dsgenl_model). For nonlinear models, the steady state is re-solved and the model re-linearized at each candidate parameter vector.
bayes_dsge(
model,
data,
priors,
chains = 2L,
iter = 5000L,
warmup = floor(iter/2),
thin = 1L,
proposal_scale = 0.1,
demean = TRUE,
seed = NULL,
n_cores = 1L,
endogenous_prior = NULL,
presample = 0L,
shock_start = NULL
)
model |
A |
data |
A data frame, matrix, or |
priors |
Named list of |
chains |
Integer. Number of MCMC chains. Default is 2. |
iter |
Integer. Total iterations per chain (warmup + sampling). Default is 5000. |
warmup |
Integer. Number of warmup iterations. Default is
|
thin |
Integer. Thinning interval. Default is 1. |
proposal_scale |
Numeric. Initial proposal standard deviation scale. Default is 0.1. |
demean |
Logical. If |
seed |
Integer. Random seed for reproducibility. If |
n_cores |
Integer. Number of CPU cores for parallel chain execution.
Set to |
endogenous_prior |
Optional |
presample |
Integer. Number of initial observations used only to
initialise the Kalman filter and excluded from the likelihood (as
Dynare's |
shock_start |
Optional named numeric vector of starting values for
the shock standard deviations (names as the shocks). Defaults to the
standard deviation of the data; for a model imported with
|
The sampler operates in unconstrained space with appropriate transformations (log for positive parameters, logit for unit-interval parameters) and Jacobian corrections. The proposal covariance is adapted during warmup to target approximately 25\
Chains are initialized by drawing from the prior. If any draw yields a non-finite log-posterior, the starting values are jittered until a valid point is found.
For nonlinear models (dsgenl_model), each posterior evaluation
involves: (1) solving the deterministic steady state at the candidate
parameters, (2) computing a first-order linearization, (3) solving
the resulting linear system, and (4) evaluating the Kalman filter
likelihood. If any stage fails (e.g., steady-state non-convergence,
Blanchard-Kahn violation), the proposal is safely rejected. This is
computationally more expensive than linear Bayesian estimation.
When n_cores > 1 each chain runs in its own R worker process,
so wall-clock time scales roughly as chains / min(n_cores, chains).
Results are numerically identical to sequential execution given the
same per-chain seeds. The parallel package (part of base R) is used;
no additional installation is required.
An object of class "dsge_bayes" containing posterior draws
and diagnostics. For nonlinear models, the result also includes
solve_failures, the number of parameter draws where steady-state,
linearization, or solution failed.
m <- dsge_model(
obs(y ~ z),
state(z ~ rho * z),
start = list(rho = 0.5)
)
set.seed(42)
z <- numeric(200); for (i in 2:200) z[i] <- 0.8 * z[i-1] + rnorm(1)
dat <- data.frame(y = z)
fit <- bayes_dsge(m, data = dat,
priors = list(rho = prior("beta", shape1 = 2, shape2 = 2)),
chains = 2, iter = 2000, seed = 1)
summary(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.