acoppock / ri2

Randomization Inference for Randomized Experiments
Other
12 stars 4 forks source link

Pipeline for Balancing table #22

Closed lucasmation closed 5 years ago

lucasmation commented 5 years ago

@acoppock , nice package, tks!

Do have any simple pipeline to produce a Balancing table based on conduct_ri for a (potentially long) set of covariates?

acoppock commented 5 years ago

I would tend to recommend a joint test (like the omnibus ri f-test in the examples, see ?conduct_ra) over a one-by-one balance table, since all those tests are correlated with each other. But that's not exactly your question!

how about something like this:

library(tidyverse)
library(ri2)
N <- 10
declaration <- declare_ra(N = N, m = 5)

dat <- tibble(X1 = rnorm(N),
              X2 = rnorm(N),
              X3 = rnorm(N),
              Z = conduct_ra(declaration))

covs <- c("X1", "X2", "X3")

balance <- 
  covs %>%
  map( ~ paste0(., " ~ Z")) %>%
  map( ~ conduct_ri(
    formula = .,
    assignment = "Z",
    declaration = declaration,
    data = dat
  )) %>%
  map_df(tidy) %>%
  mutate(covariate = covs)

balance