Simulate Trial Data from a GLM Data Generating Mechanism
Source:R/simulate_from_glm_dgm.R
simulate_from_glm_dgm.RdGenerates a simulated clinical trial dataset by sampling from the
super-population in a "glm_dgm" object. Assigns treatment
and generates outcomes from the individual-level potential outcomes
stored in the DGM.
Usage
simulate_from_glm_dgm(
dgm,
n = NULL,
rand_ratio = 1,
seed = NULL,
draw_treatment = TRUE,
replace = TRUE,
baseline = c("resample", "fixed")
)Arguments
- dgm
An object of class
"glm_dgm"created bygenerate_glm_dgm.- n
Integer. Sample size. If
NULL(default), uses the entire super-population without resampling.- rand_ratio
Numeric. Treatment:control randomisation ratio. Default
1(1:1 allocation).- seed
Integer. Random seed. Default
NULL(no explicit seed; use the calling environment's RNG state).- draw_treatment
Logical. If
TRUE(default), randomly assigns treatment. IfFALSE, retains the treatment column from the super-population.- replace
Logical sampling scheme for drawing the
nsubjects fromdgm$df_super.TRUE(default) samples with replacement (bootstrap-style trial sampling).FALSEsamples without replacement and so requiresn <= nrow(dgm$df_super); treatment is still re-randomised and the outcome re-drawn. Used to draw the full pool once (n = nrow(dgm$df_super),replace = FALSE) for the beta(Hhat) evaluation frame. Ignored on then = NULLpath.- baseline
\"resample\" (default; draw the trial panel from the super-population) or \"fixed\" (use dgm$df_source – the observed panel, every patient exactly once, observed order; requires a DGM built by a version that stores df_source; n must be NULL or nrow(df_source)).
Value
A data frame with columns:
idInteger subject identifier.
y_simSimulated outcome.
treat_simTreatment indicator (0/1).
flag_harmTrue subgroup membership indicator.
Plus all covariate columns from the super-population.
For binary outcomes, y_sim is a 0/1 Bernoulli draw from
the potential outcome probabilities (p0 or p1).
There is no event_sim column – for ForestSearch, set
event.name = "y_sim".
Examples
if (FALSE) { # \dontrun{
dgm <- generate_glm_dgm(...)
df <- simulate_from_glm_dgm(dgm, n = 500, seed = 42)
table(df$y_sim, df$treat_sim)
} # }