sim_data: Simulate a population and a randomized trial under PSPI...

View source: R/sim_data.R

sim_dataR Documentation

Simulate a population and a randomized trial under PSPI scenarios

Description

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).

Usage

sim_data(n_trial = 200, scenario = "linear", seed = NULL, prop = 0.5)

Arguments

n_trial

Integer. Target trial size; must be 200 or 60.

scenario

Character. One of "linear", "linear+covariate shift", "nonlinear", "nonlinear+covariate shift".

seed

Optional integer seed for reproducibility. If NULL, the current RNG state is used.

prop

Numeric in [0,1]. Randomization probability P(A=1) within the trial.

Value

A list with two data frames:

population

columns X1:X10, potential outcomes Y1 and Y0, selected (logical), and ps (true propensity scores of trial participation).

trials

columns X1:X10, A, and observed Y.

Examples

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)



PSPI documentation built on Dec. 2, 2025, 9:08 a.m.