Implements a generalized switching equation. Reveals observed outcomes from multiple potential outcomes variables and an assignment variable.

Usage,
reveal_outcomes(x)

Arguments

x

A formula with the outcome name on the left hand side and assignment variables on the right hand side (e.g., Y ~ Z).

Examples


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.1265327  0.1265327  0.22653270 1  0.2265327
#> 2  02  1.3631613  1.3631613  1.46316135 1  1.4631613
#> 3  03 -0.2390293 -0.2390293 -0.13902932 1 -0.1390293
#> 4  04 -0.9538384 -0.9538384 -0.85383837 0 -0.9538384
#> 5  05 -1.1681351 -1.1681351 -1.06813509 1 -1.0681351
#> 6  06  0.6278313  0.6278313  0.72783126 1  0.7278313
#> 7  07 -0.1950585 -0.1950585 -0.09505848 0 -0.1950585
#> 8  08  1.0817998  1.0817998  1.18179976 1  1.1817998
#> 9  09  2.2887418  2.2887418  2.38874181 0  2.2887418
#> 10 10 -0.5928900 -0.5928900 -0.49288997 1 -0.4928900

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 -1.44011569 -1.44011569  -1.3401157 -1.14011569 -0.54011569  0  0
#> 2  02  1.00499304  1.00499304   1.1049930  1.30499304  1.90499304  0  0
#> 3  03 -0.91661562 -0.91661562  -0.8166156 -0.61661562 -0.01661562  1  1
#> 4  04  0.82414579  0.82414579   0.9241458  1.12414579  1.72414579  1  0
#> 5  05  3.29435546  3.29435546   3.3943555  3.59435546  4.19435546  1  1
#> 6  06  0.99514871  0.99514871   1.0951487  1.29514871  1.89514871  1  0
#> 7  07  0.78008252  0.78008252   0.8800825  1.08008252  1.68008252  1  1
#> 8  08 -0.28606581 -0.28606581  -0.1860658  0.01393419  0.61393419  0  1
#> 9  09  0.04567925  0.04567925   0.1456793  0.34567925  0.94567925  1  0
#> 10 10  0.35537127  0.35537127   0.4553713  0.65537127  1.25537127  0  1
#>              Y
#> 1  -1.44011569
#> 2   1.00499304
#> 3  -0.01661562
#> 4   0.92414579
#> 5   4.19435546
#> 6   1.09514871
#> 7   1.68008252
#> 8   0.01393419
#> 9   0.14567925
#> 10  0.65537127