@@ -8,7 +8,7 @@ for each covariate, following the methodology of Chernozhukov et al.
88## Usage
99
1010``` r
11- ei_bench(spec , preproc = NULL , subset = NULL )
11+ ei_bench(spec , subset = NULL , contrast = NULL )
1212```
1313
1414## Arguments
@@ -18,19 +18,23 @@ ei_bench(spec, preproc = NULL, subset = NULL)
1818 An [ ei_spec] ( https://corymccartan.com/seine/reference/ei_spec.md )
1919 object.
2020
21- - preproc :
21+ - subset :
2222
23- An optional function which takes in a data frame of covariates and
24- returns a transformed data frame or matrix of covariates. Useful to
25- apply any preprocessing, such as a basis transformation, as part of
26- the benchmarking process. Passed to
27- [ ` rlang::as_function() ` ] ( https://rlang.r-lib.org/reference/as_function.html ) ,
28- and so supports ` purrr ` -style lambda functions.
23+ \< [ ` data-masking ` ] ( https://rlang.r-lib.org/reference/args_data_masking.html ) \>
24+ An optional indexing vector describing the subset of units over which
25+ to calculate estimates.
2926
30- - subset :
27+ - contrast :
3128
32- Passed on to
33- [ ` ei_est() ` ] ( https://corymccartan.com/seine/reference/ei_est.md ) .
29+ If provided, a list containing entries ` predictor ` and ` outcome ` , each
30+ containing a contrast vector. If only one of ` predictor ` or ` outcome `
31+ is provided, the contrast will be calculated for all levels of the
32+ other variable. For example ` list(predictor = c(1, -1, 0)) ` will
33+ calculate the difference in each outcome between the first and second
34+ predictor groups; ` list(outcome = c(1, -1)) ` will calculate the
35+ difference between the two outcomes for each predictor group; and
36+ ` list(predictor = c(1, -1, 0), outcome = c(1, -1)) ` will calculate the
37+ difference in differences.
3438
3539## References
3640
@@ -45,7 +49,6 @@ data(elec_1968)
4549
4650spec = ei_spec(elec_1968 , vap_white : vap_other , pres_ind_wal ,
4751 total = pres_total , covariates = c(educ_elem , pop_urban , farm ))
48-
4952ei_bench(spec )
5053# > # A tibble: 9 × 7
5154# > covariate predictor outcome c_outcome c_predictor confounding est_chg
@@ -60,8 +63,16 @@ ei_bench(spec)
6063# > 8 farm vap_black pres_ind_wal 0.125 0.102 0.420 0.0377
6164# > 9 farm vap_other pres_ind_wal 0.125 0.289 0.471 1.72
6265
63- # preprocess to add all 2-way interactions
64- ei_bench(spec , preproc = ~ model.matrix(~ . ^ 2 - 1 , data = .x ))
66+ # with preprocessed covariates
67+ spec = ei_spec(
68+ data = elec_1968 ,
69+ predictors = vap_white : vap_other ,
70+ outcome = pres_ind_wal ,
71+ total = pres_total ,
72+ covariates = c(educ_elem , pop_urban , farm ),
73+ preproc = ~ model.matrix(~ . ^ 2 - 1 , data = .x )
74+ )
75+ ei_bench(spec )
6576# > # A tibble: 9 × 7
6677# > covariate predictor outcome c_outcome c_predictor confounding est_chg
6778# > <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
@@ -70,8 +81,48 @@ ei_bench(spec, preproc = ~ model.matrix(~ .^2 - 1, data = .x))
7081# > 3 educ_elem vap_other pres_ind_wal 0.193 0.113 -0.549 -1.22
7182# > 4 pop_urban vap_white pres_ind_wal 0.0860 0.143 -0.586 -0.0152
7283# > 5 pop_urban vap_black pres_ind_wal 0.0860 0.210 0.526 0.0681
73- # > 6 pop_urban vap_other pres_ind_wal 0.0860 -0.345 -1 -0.359
84+ # > 6 pop_urban vap_other pres_ind_wal 0.0860 0 -1 -0.359
7485# > 7 farm vap_white pres_ind_wal 0.254 0.700 -0.294 -0.0237
7586# > 8 farm vap_black pres_ind_wal 0.254 0.617 0.486 0.160
7687# > 9 farm vap_other pres_ind_wal 0.254 1 0.162 1.08
88+ ei_bench(spec , subset = pop_urban > 0.5 )
89+ # > # A tibble: 9 × 7
90+ # > covariate predictor outcome c_outcome c_predictor confounding est_chg
91+ # > <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
92+ # > 1 educ_elem vap_white pres_ind_wal 0.193 0.797 0.181 0.0132
93+ # > 2 educ_elem vap_black pres_ind_wal 0.193 1 -0.128 -0.0486
94+ # > 3 educ_elem vap_other pres_ind_wal 0.193 0.113 -0.213 -0.472
95+ # > 4 pop_urban vap_white pres_ind_wal 0.0860 0.143 1 0.0493
96+ # > 5 pop_urban vap_black pres_ind_wal 0.0860 0.210 -1 -0.159
97+ # > 6 pop_urban vap_other pres_ind_wal 0.0860 0 -1 -0.982
98+ # > 7 farm vap_white pres_ind_wal 0.254 0.700 0.0289 0.00233
99+ # > 8 farm vap_black pres_ind_wal 0.254 0.617 0.0813 0.0268
100+ # > 9 farm vap_other pres_ind_wal 0.254 1 0.0823 0.545
101+
102+ # with contrasts
103+ spec = ei_spec(elec_1968 , vap_white : vap_other , pres_rep_nix : pres_ind_wal ,
104+ total = pres_total , covariates = c(educ_elem , pop_urban , farm ))
105+ ei_bench(spec , contrast = list (predictor = c(1 , - 1 , 0 )))
106+ # > # A tibble: 6 × 7
107+ # > covariate predictor outcome c_outcome c_predictor confounding est_chg
108+ # > <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
109+ # > 1 educ_elem vap_white - vap_… pres_r… 0.0337 1 -0.548 -0.0748
110+ # > 2 educ_elem vap_white - vap_… pres_i… 0.0852 1 0.855 0.175
111+ # > 3 pop_urban vap_white - vap_… pres_r… 0.00543 0.112 0.134 0.00327
112+ # > 4 pop_urban vap_white - vap_… pres_i… 0.0672 0.112 -0.956 -0.0773
113+ # > 5 farm vap_white - vap_… pres_r… 0.0255 0.141 0.217 0.0127
114+ # > 6 farm vap_white - vap_… pres_i… 0.123 0.141 -0.478 -0.0580
115+ ei_bench(spec , contrast = list (outcome = c(1 , - 1 )))
116+ # > # A tibble: 9 × 7
117+ # > covariate predictor outcome c_outcome c_predictor confounding est_chg
118+ # > <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
119+ # > 1 educ_elem vap_white pres_rep_nix - … 0 0.601 -1 -0.0455
120+ # > 2 educ_elem vap_black pres_rep_nix - … 0 1 1 0.204
121+ # > 3 educ_elem vap_other pres_rep_nix - … 0 1 -1 -0.125
122+ # > 4 pop_urban vap_white pres_rep_nix - … 0.00188 0.145 1 0.0197
123+ # > 5 pop_urban vap_black pres_rep_nix - … 0.00188 0.104 -1 -0.0609
124+ # > 6 pop_urban vap_other pres_rep_nix - … 0.00188 0.0365 -0.822 -0.544
125+ # > 7 farm vap_white pres_rep_nix - … 0.00722 0.260 0.749 0.0238
126+ # > 8 farm vap_black pres_rep_nix - … 0.00722 0.102 -0.577 -0.0468
127+ # > 9 farm vap_other pres_rep_nix - … 0.00722 0.226 -0.691 -2.05
77128```
0 commit comments