Calibrate GLM Interaction for a Target Subgroup Effect Size
Source:R/calibrate_glm_interaction.R
calibrate_glm_interaction.RdSearches over a grid of interaction multipliers (k_inter) to find
the value that produces a target effect size in the subgroup \(Q\).
Returns a modified "glm_dgm" object with the calibrated
interaction and updated true effects.
Usage
calibrate_glm_interaction(
data,
factor_vars,
continuous_vars = NULL,
outcome_var,
treatment_var,
target_effect,
outcome_type = c("binary", "continuous", "count"),
effect_measure = NULL,
offset_var = NULL,
subgroup_vars = NULL,
subgroup_cuts = NULL,
k_treat = 1,
adverse_outcome = FALSE,
k_inter_range = c(-10, 10),
grid_step = 0.05,
tol_rel = 2.5,
n_super = 5000L,
seed = 8316951L,
verbose = FALSE
)Arguments
- data
The source data frame (same as passed to
generate_glm_dgm).- factor_vars
Character vector of factor variable names.
- continuous_vars
Character vector of continuous prognostic variable names. Passed through to
generate_glm_dgm. DefaultNULL.- outcome_var
Character string naming the outcome variable.
- treatment_var
Character string naming the treatment variable.
- target_effect
Numeric. Target effect size in Q on the scale determined by
effect_measure(e.g., OR = 2.0 for a binary outcome).- outcome_type
Character. One of
"binary","continuous", or"count".- effect_measure
Character. Effect measure. Default
NULL(selects default peroutcome_type).- offset_var
Character or
NULL. Name of the exposure / follow-up time column for count outcomes with an offset (IRR, IRD). DefaultNULL.- subgroup_vars
Character vector of subgroup-defining variables.
- subgroup_cuts
Named list of cutpoint specifications.
- k_treat
Numeric. Treatment effect scaling factor passed to
generate_glm_dgm. Default1(preserve fitted treatment effect). Set to0to zero out the ITT effect.- adverse_outcome
Logical. When
TRUEfor binary outcomes with a ratio effect measure (OR, RR), the calibration searches for1 / target_effecton the actual Y scale becausegenerate_glm_dgmnegatesk_interinternally. The returned DGM storesadverse_outcome = TRUEso that downstream functions (e.g.,run_simulation_analysis) can auto-coordinate the analysis direction. DefaultFALSE.- k_inter_range
Numeric vector of length 2. Search range for
k_inter. Defaultc(0, 10).- grid_step
Numeric. Grid resolution. Default
0.05.- tol_rel
Numeric. Maximum tolerated relative error, in percent; the call stops (fails loudly) if the achieved OR is not within
tol_relpercent of the target. Default2.5.- n_super
Integer. Super-population size. Default
5000L.- seed
Integer. Random seed. Default
8316951L.- verbose
Logical. Print calibration progress. Default
FALSE.
Details
The function constructs a grid of k_inter values, calls
generate_glm_dgm for each, and selects the value
whose subgroup effect is closest to target_effect.
For binary outcomes with effect_measure = "OR", the target
is on the switched-treatment OR scale (OR > 1 = treatment increases
the outcome).
Examples
if (FALSE) { # \dontrun{
dgm <- calibrate_glm_interaction(
data = actg_df,
factor_vars = paste0("z", 1:12),
outcome_var = "y_binary",
treatment_var = "treat",
target_effect = 2.0,
outcome_type = "binary",
subgroup_vars = c("z1", "z2"),
subgroup_cuts = list(z1 = 1L, z2 = 1L),
verbose = TRUE
)
print(dgm)
} # }