Skip to contents

Plots posterior structural-shock contributions over the full sample or after aggregation over selected historical periods.

Usage

plot_hd_lines(
  object,
  probability = 0.9,
  variables = NULL,
  shocks = NULL,
  models = NULL,
  facet_scales = "free_y",
  include_observed = FALSE,
  include_baseline = FALSE,
  shock_groups = NULL,
  top_n = NULL,
  collapse_other = TRUE,
  by = c("variable", "shock"),
  model = "model1",
  ...
)

Arguments

object

A posterior model object, PosteriorHD, or a tidy table of historical decompositions. Plots that reconstruct the observed series require a posterior model. Combining multiple shocks, including an "Other" component, requires draw-level input: marginal medians and interval bounds cannot be added. Ungrouped summary tables remain supported.

probability

Probability mass of the equal-tailed credible interval computed when object is not already a summary table.

variables

Variables whose historical decompositions are included.

shocks

Structural shocks whose contributions are included.

models

Model specifications to include.

facet_scales

Facet scales passed to ggplot2.

include_observed

If TRUE, include the observed series for plot types that compare decomposition totals against the realised path.

include_baseline

If TRUE, include the non-shock baseline component when building a full decomposition. The baseline is computed before filtering shocks. Displayed marginal medians need not add up to the median of the decomposition total.

shock_groups

Optional named character vector mapping shock names to display groups.

top_n

Optional number of largest contributors to retain within each model-variable panel.

collapse_other

If TRUE, contributors outside top_n (or unmapped shocks under shock_groups) are collapsed into "Other".

by

One of "variable" or "shock" for line-based displays.

model

Model label used when converting posterior objects to posterior-summary tables.

...

Additional arguments passed to tidy_hd() or tidy_hd_event() when conversion is required.

Value

A ggplot object.

Examples

# \donttest{
data(us_fiscal_lsuw, package = "bsvars")
spec <- bsvars::specify_bsvar$new(us_fiscal_lsuw, p = 1)
#> The identification is set to the default option of lower-triangular structural matrix.
post <- bsvars::estimate(spec, S = 5, show_progress = FALSE)

hd_tbl <- tidy_hd(post)
p_lines <- plot_hd_lines(hd_tbl, variables = "gdp")
p_overlay <- plot_hd_overlay(post, variables = "gdp")
p_stacked <- plot_hd_stacked(post, variables = "gdp")
p_total <- plot_hd_total(post, variables = "gdp", shocks = "gs")

hd_times <- unique(as.character(tidy_hd(post, draws = TRUE)$time))
p_share <- plot_hd_event_share(post, start = hd_times[1], end = hd_times[2])
p_cum <- plot_hd_event_cumulative(post, start = hd_times[1], end = hd_times[2])
p_dist <- plot_hd_event_distribution(post, start = hd_times[1], end = hd_times[2])
# }