DeclareDesign Community

Storage error when expanding designs using vectors defined outside expand_design()

When vectors over which I want to expand a design are defined outside of expand_design(), the values over which I expanded are not stored. See the reprex below.

A short version:

This works:

expand_design(..., samp_size = 1:2)

This does not store the parameters:

ss <- 1:2
expand_design(..., samp_size = ss)
# Storage Problem MWE

library(DeclareDesign)
#> Loading required package: randomizr
#> Loading required package: fabricatr
#> Loading required package: estimatr
library(tidyverse)

# Create simple designer:

simple_designer <- function(pop_size = 100, effect_size, samp_size) {
  declare_model(
    N = pop_size,
    U = rnorm(N),
    potential_outcomes(Y ~ effect_size * Z + U)
  ) +
    declare_inquiry(PATE = mean(Y_Z_1 - Y_Z_0)) +
    declare_sampling(S = complete_rs(N, n = samp_size), legacy = FALSE) +
    declare_assignment(
      Z = complete_ra(N, prob = 0.5), legacy = FALSE
    ) +
    declare_measurement(Y = reveal_outcomes(Y ~ Z)) +
    declare_estimator(
      Y ~ Z, model = difference_in_means, inquiry = "PATE"
    )
}

# Set sample sizes and treatment effects to test:

ss <- c(10, 20, 30)
tes <- c(.5, 1.5, 3)

# Create designs:

designs <- expand_design(
  simple_designer,
  samp_size = ss,
  effect_size = tes
)

# Diagnose them:

diag_des <- diagnose_design(designs)

# Sample sizes and TEs *not* stored.
# See columns 2 and 3.

diag_des$diagnosands_df %>% head(4) %>% select(1:7)
#>   design_label samp_size effect_size inquiry_label estimator_label term
#> 1     design_1        ss         tes          PATE       estimator    Z
#> 2     design_2      <NA>         tes          PATE       estimator    Z
#> 3     design_3      <NA>         tes          PATE       estimator    Z
#> 4     design_4        ss        <NA>          PATE       estimator    Z
#>           bias
#> 1 -0.021417965
#> 2 -0.031835059
#> 3 -0.005183475
#> 4 -0.021602474

# But, if I define the argument vectors directly, storage succeeds.

# Set sample sizes and treatment effects directly in expand_design():

designs <- expand_design(
  simple_designer,
  samp_size = c(10, 20, 30),
  effect_size = c(.5, 1.5, 3)
)

# Diagnose them:

diag_des <- diagnose_design(designs)

# Sample sizes and TEs are stored.
# See columns 2 and 3.

diag_des$diagnosands_df %>% head(4) %>% select(1:7)
#>   design_label samp_size effect_size inquiry_label estimator_label term
#> 1     design_1        10         0.5          PATE       estimator    Z
#> 2     design_2        20         0.5          PATE       estimator    Z
#> 3     design_3        30         0.5          PATE       estimator    Z
#> 4     design_4        10         1.5          PATE       estimator    Z
#>            bias
#> 1 -0.0197979989
#> 2 -0.0332026529
#> 3 -0.0002053414
#> 4 -0.0203909875

Created on 2021-04-08 by the reprex package (v2.0.0)

Thank you @ryantmoore for this fully worked example! This is indeed a bug – I’ve reported it here and we’ll see about fixing it. Expand_design not passing through parameters · Issue #466 · DeclareDesign/DeclareDesign · GitHub

1 Like