| sim_data | R Documentation |
Generates a finite population of size 1000 with seven continuous and three
binary covariates, constructs potential outcomes Y0 and Y1
according to the chosen scenario, simulates trial participation through a
logistic selection model calibrated to target n_trial = 200 or 60,
and returns both the target population and the randomized trial
(with treatment assigned at probability prop).
sim_data(n_trial = 200, scenario = "linear", seed = NULL, prop = 0.5)
n_trial |
Integer. Target trial size; must be |
scenario |
Character. One of |
seed |
Optional integer seed for reproducibility. If |
prop |
Numeric in |
A list with two data frames:
columns X1:X10, potential outcomes Y1 and Y0,
selected (logical), and ps (true propensity scores of trial participation).
columns X1:X10, A, and observed Y.
set.seed(2025)
sim <- sim_data(n_trial = 200, scenario = "nonlinear", prop = 0.5)
str(sim$population)
table(sim$trials$A) # treatment allocation
mean(sim$population$selected) # selection rate
# A smaller trial size and linear scenario with covariate shift
sim2 <- sim_data(n_trial = 60, scenario = "linear+covariate shift", seed = 1, prop = 0.6)
nrow(sim2$trials)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.