| run_eba | R Documentation |
Runs an Extreme-Bounds Analysis (EBA) over a predefined set of control
variable combinations, fitting (or re-fitting) the bivariate hurdle
model for each combination and extracting posterior mean coefficients
for all regression blocks (mu_I, pi_I, mu_C,
pi_C).
run_eba(
DT,
spec = "C",
control_combos,
k_bma_table = NULL,
seed = 123,
dir_csv = NULL
)
DT |
A |
spec |
Character scalar; model specification (e.g.\ |
control_combos |
A named list whose names are control tags
(e.g.\ |
k_bma_table |
Optional object (typically a named list or
|
seed |
Integer; base random seed for the fits. For different control combinations, the seed is jittered to avoid identical pseudo-random sequences. |
dir_csv |
Character scalar or |
This function relies on fit_one(), which requires
cmdstanr and a working CmdStan installation.
For each control-combination tag tag:
If a BMA weights file
"bma_weights_spec<spec>_ctrl<tag>.csv" exists in
dir_csv and k_bma_table[[tag]] is not NULL,
the top-weighted row (highest weight) is used to select
k and horseshoe hyperparameters (hs_tau0,
hs_slab_scale, hs_slab_df) for the fit.
Otherwise, the model is fit with k = 2 and default
horseshoe hyperparameters.
Posterior means of the regression coefficients with prefixes
"b_mu_I", "b_pi_I", "b_mu_C",
"b_pi_C" are extracted and mapped back to the corresponding
column names of the design matrices.
All coefficient summaries are stacked into a single table and, when
dir_csv is supplied, written to "eba_coefficients.csv" in
that directory.
A data.frame with the columns:
name: name of the covariate (design-matrix column).
mean: posterior mean of the corresponding coefficient.
block: block identifier ("mu_I", "pi_I",
"mu_C", "pi_C").
combo: control-combination tag used for that fit.
# This example fits Stan models and therefore runs only in an
# interactive session with 'cmdstanr' and a working CmdStan.
if (interactive() && requireNamespace("cmdstanr", quietly = TRUE)) {
DT <- data.table::data.table(
I = rpois(21, lambda = 4),
C = rpois(21, lambda = 3),
zI = rnorm(21),
zC = rnorm(21),
t_norm = seq(-1, 1, length.out = 21),
t_poly2 = seq(-1, 1, length.out = 21)^2,
Regime = factor(sample(c("A", "B"), 21, replace = TRUE)),
trans_PS = sample(0:1, 21, replace = TRUE),
trans_SF = sample(0:1, 21, replace = TRUE),
trans_FC = sample(0:1, 21, replace = TRUE),
log_exposure50 = rep(0, 21),
X1 = rnorm(21), X2 = rnorm(21), X3 = rnorm(21)
)
combos <- list(
None = character(0),
"X1+X2" = c("X1", "X2"),
"X1+X2+X3" = c("X1", "X2", "X3")
)
eba_tab <- run_eba(DT, spec = "C", control_combos = combos, seed = 123)
print(head(eba_tab))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.