| contrafactual_ATE | R Documentation |
Computes time-varying contrafactual Average Treatment Effects (ATE) for
both series (I and C) from a fitted bivariate hurdle
negative binomial model. For each time point and posterior draw, the
function compares the expected outcome under the observed design matrix
with a contrafactual scenario where cross-lag terms and transition
covariates are set to zero.
contrafactual_ATE(fit_obj, compute_intervals = TRUE, ndraws = 1200, seed = 42)
fit_obj |
A list returned by
|
compute_intervals |
Logical; if |
ndraws |
Integer; maximum number of posterior draws to use. If
|
seed |
Integer; random seed used to subsample posterior draws. |
The function identifies in the design matrices:
Cross-lag terms via column names containing
"zC_L" / "C_L" (for I) and
"zI_L" / "I_L" (for C).
Transition covariates via column names starting with
"trans_".
For each time point t and posterior draw s, the expected
value under the observed design (E[Y \mid X]) is contrasted with
a contrafactual design where these cross-lag and transition columns are
set to zero (E[Y \mid X_{cf}]). The ATE at time t is
defined as the posterior distribution of E[Y \mid X] -
E[Y \mid X_{cf}], computed separately for I and C.
A tibble with one row per effective time index (length
des$idx). If compute_intervals = TRUE, the columns are:
t: time index (from des$idx).
ATE_I_mean, ATE_I_low, ATE_I_high:
posterior mean and 95\
ATE_C_mean, ATE_C_low, ATE_C_high:
posterior mean and 95\
If compute_intervals = FALSE, only ATE_I_mean and
ATE_C_mean are returned (plus t).
if (interactive() && requireNamespace("cmdstanr", quietly = TRUE)) {
n <- 120
DT <- data.table::data.table(
I = rpois(n, 5), C = rpois(n, 3),
Regime = factor(sample(c("A","B","C"), n, TRUE)),
trans_PS = c(rep(1,5), rep(0,n-5)),
trans_SF = c(rep(0,60), rep(1,5), rep(0,n-65)),
trans_FC = rep(0, n),
log_exposure50 = log(runif(n, 40, 60))
)
fit_obj <- fit_one(DT, k = 1, spec = "C")
ate_tab <- contrafactual_ATE(fit_obj, compute_intervals = TRUE)
head(ate_tab)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.