
Estimate Marginal Subgroup Treatment Effects
Source:R/estimate_subgroup_effects.R
estimate_subgroup_effects.RdThe function uses a counterfactual, marginal approach based on the posterior predictive distribution. It averages over all other covariates to provide robust estimates of subgroup-specific effects.
Usage
estimate_subgroup_effects(
brms_fit,
trt_var = NULL,
data = NULL,
subgroup_vars = "auto",
response_type = NULL,
ndraws = NULL
)Arguments
- brms_fit
A
brmsfitobject. Fitted model object fromfit_brms_model()orrun_brms_analysis(). Must contain the necessary attributes for extracting treatment variable and response type information.- trt_var
A character string or
NULL. Treatment variable name. IfNULL, automatically extracted from model attributes (set byfit_brms_model()). Must be a binary variable coded as 0/1 in the dataset.- data
A data frame or
NULL. Dataset used for model fitting. IfNULL, automatically extracted from model attributes (set byfit_brms_model()). This dataset is used for generating counterfactual predictions.- subgroup_vars
A character vector or
"auto". Subgroup variable names for which to estimate treatment effects. If"auto"(default), automatically detects treatment interaction terms (colon syntax) and random effect grouping factors (pipe syntax) from all formula components (unshrunktermeffect,shprogeffect,shpredeffect).- response_type
A character string or
NULL. Outcome type, one of"binary","count","continuous", or"survival". IfNULL, automatically extracted from model attributes (set byfit_brms_model()). This determines the appropriate scale for effect estimation.- ndraws
An integer or
NULL. Number of posterior draws to use for estimation. IfNULL(default), all available posterior draws are used. Reducing this can speed up computation at the cost of precision.