Skip to contents

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.1309714  0.1309714  0.23097144 1  0.23097144
#> 2  02  1.7630634  1.7630634  1.86306342 1  1.86306342
#> 3  03 -1.1992859 -1.1992859 -1.09928586 0 -1.19928586
#> 4  04 -0.9795209 -0.9795209 -0.87952086 1 -0.87952086
#> 5  05  0.2774011  0.2774011  0.37740110 1  0.37740110
#> 6  06  0.1006283  0.1006283  0.20062826 0  0.10062826
#> 7  07  0.9345750  0.9345750  1.03457497 1  1.03457497
#> 8  08  1.0814312  1.0814312  1.18143124 1  1.18143124
#> 9  09 -0.2506998 -0.2506998 -0.15069982 1 -0.15069982
#> 10 10 -0.1629671 -0.1629671 -0.06296714 1 -0.06296714

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 -2.11397293 -2.11397293 -2.01397293  -1.8139729  -1.2139729  0  0
#> 2  02  0.08984290  0.08984290  0.18984290   0.3898429   0.9898429  1  1
#> 3  03  0.29558527  0.29558527  0.39558527   0.5955853   1.1955853  1  1
#> 4  04  2.01912148  2.01912148  2.11912148   2.3191215   2.9191215  0  1
#> 5  05  0.17098122  0.17098122  0.27098122   0.4709812   1.0709812  0  0
#> 6  06  0.75039255  0.75039255  0.85039255   1.0503926   1.6503926  1  0
#> 7  07 -1.66134684 -1.66134684 -1.56134684  -1.3613468  -0.7613468  1  1
#> 8  08 -0.01526542 -0.01526542  0.08473458   0.2847346   0.8847346  1  1
#> 9  09  0.93015879  0.93015879  1.03015879   1.2301588   1.8301588  0  0
#> 10 10 -2.60630394 -2.60630394 -2.50630394  -2.3063039  -1.7063039  1  0
#>             Y
#> 1  -2.1139729
#> 2   0.9898429
#> 3   1.1955853
#> 4   2.3191215
#> 5   0.1709812
#> 6   0.8503926
#> 7  -0.7613468
#> 8   0.8847346
#> 9   0.9301588
#> 10 -2.5063039