plot.dsge_bayes: Plot Bayesian DSGE Results

View source: R/bayes-methods.R

plot.dsge_bayesR Documentation

Plot Bayesian DSGE Results

Description

Produces diagnostic plots for posterior draws from a Bayesian DSGE fit.

Usage

## S3 method for class 'dsge_bayes'
plot(
  x,
  type = c("trace", "density", "prior_posterior", "running_mean", "acf", "pairs", "all",
    "irf"),
  pars = NULL,
  ...
)

Arguments

x

A dsge_bayes object from bayes_dsge().

type

Character. Plot type:

"trace"

Trace plots showing MCMC chains for each parameter. All chains are overlaid with distinct colors. Useful for assessing convergence and mixing.

"density"

Posterior density plots for each parameter with the prior distribution overlaid as a red dashed line. Useful for seeing how much the data updated the prior.

"prior_posterior"

Dedicated prior-vs-posterior comparison. Same layout as "density" but with the title "Prior vs Posterior" to emphasize the comparison.

"running_mean"

Cumulative posterior mean by iteration for each parameter. All chains are shown. Useful for assessing whether the chain has settled.

"acf"

Autocorrelation function plots for each parameter, pooled across chains. Useful for diagnosing slow mixing.

"pairs"

Pairwise scatter plots of posterior draws (lower triangle) with correlation coefficients (upper triangle) and marginal histograms (diagonal). Useful for detecting parameter correlations. Draws are thinned for readability.

"all"

A combined diagnostic panel showing trace plot (left) and posterior density with prior (right) side by side for each parameter.

"irf"

Posterior impulse-response functions with credible bands. Calls irf() internally and plots the result. Additional arguments periods, impulse, response, n_draws, and level are passed through.

pars

Character vector of parameter names to include. If NULL (default), all parameters are shown. Applies to trace, density, prior_posterior, running_mean, acf, pairs, and all. Ignored for irf (use impulse/response instead).

...

Additional arguments. For type = "irf", arguments periods, impulse, response, n_draws, and level are passed to irf.dsge_bayes().

Details

All plot types except pairs and irf handle any number of parameters by paginating across multiple plot pages (up to 4 parameters per page). In interactive sessions, devAskNewPage() is used to prompt between pages.

For the "pairs" plot, at most 1000 draws are used to keep the plot readable. The correlation matrix is printed to the console.

Forecast plotting is not currently supported for Bayesian fits. Use irf() for posterior impulse-response analysis.

Value

Invisibly returns the dsge_bayes object x. Called for the side effect of producing diagnostic plots on the active graphics device.

Examples


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)
fit <- bayes_dsge(m, data = data.frame(y = z),
                  priors = list(rho = prior("beta", shape1 = 2, shape2 = 2)),
                  chains = 2, iter = 2000, seed = 1)
plot(fit, type = "trace")
plot(fit, type = "density")
plot(fit, type = "prior_posterior")
plot(fit, type = "running_mean")
plot(fit, type = "acf")
plot(fit, type = "all")
# Parameter selection
plot(fit, type = "trace", pars = "rho")



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