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

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.5673181  0.5673181  0.6673181 1  0.6673181
#> 2  02  0.7043605  0.7043605  0.8043605 0  0.7043605
#> 3  03  1.3209924  1.3209924  1.4209924 0  1.3209924
#> 4  04  0.8864451  0.8864451  0.9864451 0  0.8864451
#> 5  05  0.5588969  0.5588969  0.6588969 0  0.5588969
#> 6  06  0.2101449  0.2101449  0.3101449 0  0.2101449
#> 7  07 -0.4369102 -0.4369102 -0.3369102 0 -0.4369102
#> 8  08  0.4318512  0.4318512  0.5318512 1  0.5318512
#> 9  09 -0.6456359 -0.6456359 -0.5456359 0 -0.6456359
#> 10 10 -0.3502823 -0.3502823 -0.2502823 0 -0.3502823

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.18006983 -0.18006983 -0.08006983   0.1199302   0.7199302  1  1
#> 2  02 -0.50529564 -0.50529564 -0.40529564  -0.2052956   0.3947044  0  0
#> 3  03 -1.07693835 -1.07693835 -0.97693835  -0.7769384  -0.1769384  0  0
#> 4  04  1.30743596  1.30743596  1.40743596   1.6074360   2.2074360  1  0
#> 5  05  0.43191932  0.43191932  0.53191932   0.7319193   1.3319193  1  0
#> 6  06  0.24205469  0.24205469  0.34205469   0.5420547   1.1420547  0  1
#> 7  07 -0.02047123 -0.02047123  0.07952877   0.2795288   0.8795288  1  1
#> 8  08 -0.02921057 -0.02921057  0.07078943   0.2707894   0.8707894  0  0
#> 9  09  0.48977904  0.48977904  0.58977904   0.7897790   1.3897790  1  0
#> 10 10  0.19403637  0.19403637  0.29403637   0.4940364   1.0940364  0  0
#>              Y
#> 1   0.71993017
#> 2  -0.50529564
#> 3  -1.07693835
#> 4   1.40743596
#> 5   0.53191932
#> 6   0.54205469
#> 7   0.87952877
#> 8  -0.02921057
#> 9   0.58977904
#> 10  0.19403637