You can also write a design maker function that declares a design based on a set of parameters like `N`

, the number of clusters, etc. and use the function `fill_out()`

to make designs using just those parameters.

```
m_arm_trial <- function(numb){
my_population <- declare_population(
N = numb, income = rnorm(N), age = sample(18:95, N, replace = T))
my_potential_outcomes <- declare_potential_outcomes(
formula = Y ~ .25 * Z + .01 * age * Z)
my_sampling <- declare_sampling(n = 250)
my_assignment <- declare_assignment(m = 25)
my_estimand <- declare_estimand(ATE = mean(Y_Z_1 - Y_Z_0))
my_estimator_dim <- declare_estimator(Y ~ Z, estimand = my_estimand)
my_design <- declare_design(my_population,
my_potential_outcomes,
my_estimand,
my_sampling,
my_assignment,
reveal_outcomes,
my_estimator_dim)
return(my_design)
}
my_1000_design <- fill_out(template = m_arm_trial, numb = 1000)
head(draw_data(my_1000_design))
```

ID | income | age | Y_Z_0 | Y_Z_1 | S_inclusion_prob | Z | Z_cond_prob | Y | |
---|---|---|---|---|---|---|---|---|---|

6 | 0006 | -0.91 | 51 | 0 | 0.76 | 0.25 | 0 | 0.9 | 0 |

9 | 0009 | 0.86 | 40 | 0 | 0.65 | 0.25 | 0 | 0.9 | 0 |

10 | 0010 | -0.10 | 75 | 0 | 1.00 | 0.25 | 0 | 0.9 | 0 |

19 | 0019 | 0.69 | 21 | 0 | 0.46 | 0.25 | 0 | 0.9 | 0 |

22 | 0022 | -0.05 | 55 | 0 | 0.80 | 0.25 | 0 | 0.9 | 0 |

26 | 0026 | -1.38 | 51 | 0 | 0.76 | 0.25 | 0 | 0.9 | 0 |

```
my_potential_outcomes_continuous <- declare_potential_outcomes(
formula = Y ~ .25 * Z + .01 * age * Z, conditions = seq(0, 1, by = .1))
continuous_treatment_function <- function(data){
data$Z <- sample(seq(0, 1, by = .1), size = nrow(data), replace = TRUE)
data
}
my_assignment_continuous <- declare_assignment(handler = continuous_treatment_function)
my_design <- declare_design(my_population(),
my_potential_outcomes_continuous,
my_assignment_continuous,
reveal_outcomes)
head(draw_data(my_design))
```

ID | income | age | Y_Z_0 | Y_Z_0.1 | Y_Z_0.2 | Y_Z_0.3 | Y_Z_0.4 | Y_Z_0.5 | Y_Z_0.6 | Y_Z_0.7 | Y_Z_0.8 | Y_Z_0.9 | Y_Z_1 | Z | Y |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|

0001 | -0.38 | 73 | 0 | 0.10 | 0.20 | 0.29 | 0.39 | 0.49 | 0.59 | 0.69 | 0.78 | 0.88 | 0.98 | 0.3 | 0.29 |

0002 | -0.80 | 36 | 0 | 0.06 | 0.12 | 0.18 | 0.24 | 0.30 | 0.37 | 0.43 | 0.49 | 0.55 | 0.61 | 0.3 | 0.18 |

0003 | 1.54 | 26 | 0 | 0.05 | 0.10 | 0.15 | 0.20 | 0.26 | 0.31 | 0.36 | 0.41 | 0.46 | 0.51 | 0.0 | 0.00 |

0004 | -0.77 | 19 | 0 | 0.04 | 0.09 | 0.13 | 0.18 | 0.22 | 0.26 | 0.31 | 0.35 | 0.40 | 0.44 | 0.5 | 0.22 |

0005 | -0.07 | 50 | 0 | 0.08 | 0.15 | 0.23 | 0.30 | 0.38 | 0.45 | 0.52 | 0.60 | 0.68 | 0.75 | 0.5 | 0.38 |

0006 | -1.12 | 56 | 0 | 0.08 | 0.16 | 0.24 | 0.32 | 0.40 | 0.49 | 0.57 | 0.65 | 0.73 | 0.81 | 0.5 | 0.40 |

Attrition can be thought of as just another potential outcome. That is, one describe possible attrition processes, include them in the design, and see how estimation strategies are affected by these processes. Here is an example.

```
my_potential_outcomes_attrition <- declare_potential_outcomes(
formula = R ~ rbinom(n = N, size = 1, prob = pnorm(Y_Z_0)))
my_design <- declare_design(my_population(),
my_potential_outcomes,
my_potential_outcomes_attrition,
my_assignment,
reveal_outcomes(outcome_variables = "R"),
reveal_outcomes(attrition_variables = "R"))
head(draw_data(my_design)[, c("ID", "Y_Z_0", "Y_Z_1", "R_Z_0", "R_Z_1", "Z", "R", "Y")])
```

ID | Y_Z_0 | Y_Z_1 | R_Z_0 | R_Z_1 | Z | R | Y |
---|---|---|---|---|---|---|---|

0001 | 0 | 1.13 | 1 | 1 | 0 | 1 | 0 |

0002 | 0 | 1.04 | 0 | 1 | 0 | 0 | NA |

0003 | 0 | 0.90 | 1 | 1 | 0 | 1 | 0 |

0004 | 0 | 1.14 | 1 | 1 | 0 | 1 | 0 |

0005 | 0 | 0.73 | 0 | 0 | 0 | 0 | NA |

0006 | 0 | 1.16 | 1 | 0 | 0 | 1 | 0 |

The population (or any level of the population) can have stochastic population sizes. (In fact, N can be a number, a fixed vector of numbers, or an expression that returns a stochastic number or vector of numbers.)

```
stochastic_population <- declare_population(
N = sample(500:1000, 1), income = rnorm(N), age = sample(18:95, N, replace = TRUE))
c(nrow(stochastic_population()),
nrow(stochastic_population()),
nrow(stochastic_population()))
```

880, 640, 764