Implements a generalized switching equation. Reveals observed outcomes from multiple potential outcomes variables and an assignment variable.
reveal_outcomes(x)
A formula with the outcome name on the left hand side and assignment variables on the right hand side (e.g., Y ~ Z
).
dat <- fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z + U)
)
fabricate(
data = dat,
Z = rbinom(N, 1, prob = 0.5),
Y = reveal_outcomes(Y ~ Z)
)
#> ID U Y_Z_0 Y_Z_1 Z Y
#> 1 01 0.07116222 0.07116222 0.17116222 1 0.17116222
#> 2 02 -1.62866912 -1.62866912 -1.52866912 0 -1.62866912
#> 3 03 0.45553573 0.45553573 0.55553573 0 0.45553573
#> 4 04 1.15905403 1.15905403 1.25905403 0 1.15905403
#> 5 05 -0.07415683 -0.07415683 0.02584317 0 -0.07415683
#> 6 06 0.95217676 0.95217676 1.05217676 0 0.95217676
#> 7 07 -0.97325304 -0.97325304 -0.87325304 1 -0.87325304
#> 8 08 -1.22319230 -1.22319230 -1.12319230 1 -1.12319230
#> 9 09 0.87807227 0.87807227 0.97807227 0 0.87807227
#> 10 10 -0.82158741 -0.82158741 -0.72158741 1 -0.72158741
fabricate(
N = 10,
U = rnorm(N),
potential_outcomes(Y ~ 0.1 * Z1 + 0.3 * Z2 + 0.5 * Z1 * Z2 + U,
conditions = list(Z1 = c(0, 1),
Z2 = c(0, 1))),
Z1 = rbinom(N, 1, prob = 0.5),
Z2 = rbinom(N, 1, prob = 0.5),
Y = reveal_outcomes(Y ~ Z1 + Z2)
)
#> ID U Y_Z1_0_Z2_0 Y_Z1_1_Z2_0 Y_Z1_0_Z2_1 Y_Z1_1_Z2_1 Z1 Z2
#> 1 01 0.6953996 0.6953996 0.7953996 0.99539963 1.5953996 0 0
#> 2 02 -0.3182750 -0.3182750 -0.2182750 -0.01827496 0.5817250 0 0
#> 3 03 0.7425124 0.7425124 0.8425124 1.04251240 1.6425124 1 1
#> 4 04 -1.0792287 -1.0792287 -0.9792287 -0.77922870 -0.1792287 1 0
#> 5 05 -0.6493430 -0.6493430 -0.5493430 -0.34934298 0.2506570 1 0
#> 6 06 0.4243891 0.4243891 0.5243891 0.72438915 1.3243891 0 1
#> 7 07 1.2771314 1.2771314 1.3771314 1.57713138 2.1771314 1 1
#> 8 08 0.9717922 0.9717922 1.0717922 1.27179224 1.8717922 0 1
#> 9 09 -0.2465042 -0.2465042 -0.1465042 0.05349579 0.6534958 0 1
#> 10 10 0.7957069 0.7957069 0.8957069 1.09570690 1.6957069 0 1
#> Y
#> 1 0.69539963
#> 2 -0.31827496
#> 3 1.64251240
#> 4 -0.97922870
#> 5 -0.54934298
#> 6 0.72438915
#> 7 2.17713138
#> 8 1.27179224
#> 9 0.05349579
#> 10 1.09570690