# Two-arm randomized experiment
design <-
declare_model(
N = 500,
gender = rbinom(N, 1, 0.5),
X = rep(c(0, 1), each = N / 2),
U = rnorm(N, sd = 0.25),
potential_outcomes(Y ~ 0.2 * Z + X + U)
) +
declare_inquiry(ATE = mean(Y_Z_1 - Y_Z_0)) +
declare_sampling(S = complete_rs(N = N, n = 200)) +
declare_assignment(Z = complete_ra(N = N, m = 100)) +
declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
declare_estimator(Y ~ Z, inquiry = "ATE")
if (FALSE) {
# Simulate design
simulations <- simulate_design(design, sims = 100)
simulations
# Diagnose design using simulations
diagnosis <- diagnose_design(simulations_df = simulations)
diagnosis
# Simulate one part of the design for a fixed population
# (The 100 simulates different assignments)
head(simulate_design(design, sims = c(1, 1, 1, 100, 1, 1)))
# You may also run simulate_design in parallel using
# the future package on a personal computer with multiple
# cores or on high performance computing clusters.
library(future)
options(parallelly.fork.enable = TRUE) # required for use in RStudio
plan(multicore) # note other plans are possible, see future
simulate_design(design, sims = 500)
}
Run the code above in your browser using DataLab