Computes IRFs for network-level statistics given a shock.
Important: ggplot2 exports its own stat_density function,
which masks dbn::stat_density when both packages are loaded.
If you use ggplot2, pass the statistic explicitly:
stat_fun = dbn::stat_density.
Usage
compute_irf(
fit,
shock,
H = 20,
t0 = 1,
stat_fun = stat_density,
n_draws = NULL,
shock_pars = list(),
...
)Arguments
- fit
A dbn model fit object
- shock
Shock matrix or shock type (see
build_shock)- H
Number of horizons to compute
- t0
Shock time for dynamic models
- stat_fun
Network statistic function (default:
stat_density). Must accept a matrix and return a scalar. Whenggplot2is loaded, usedbn::stat_densityexplicitly to avoid name masking.- n_draws
Number of posterior draws to use
- shock_pars
List of parameters for
build_shockifshockis a character string- ...
Additional arguments
Examples
# \donttest{
sim <- simulate_dynamic_dbn(n = 6, time = 10, seed = 1)
fit <- dbn(sim$Y, model = "dynamic", nscan = 200, burn = 100, verbose = FALSE)
S <- build_shock(m = 6, type = "unit_edge", i = 1, j = 2)
irf <- compute_irf(fit, shock = S, H = 5, stat_fun = dbn::stat_density)
print(irf)
#> Network Impulse Response Function
#> Model: dynamic
#> Statistic: custom_function
#> Shock time: 1
#>
#> Summary:
#> horizon mean median sd q025 q975 q10 q90
#> 1 0 0.033 0.033 0.000 0.033 0.033 0.033 0.033
#> 2 1 0.002 0.001 0.036 -0.065 0.096 -0.042 0.043
#> 3 2 -0.003 0.000 0.056 -0.096 0.096 -0.055 0.041
#> 4 3 -0.005 -0.003 0.057 -0.106 0.088 -0.057 0.051
#> 5 4 -0.014 -0.001 0.061 -0.192 0.075 -0.086 0.038
#> 6 5 0.011 0.000 0.097 -0.128 0.237 -0.050 0.064
# }