Hi Everyone!

I am new to DD. I am trying to declare and diagnose (with plots) a full factorial design (2x2x2, each arm has equal probability ) to include in the PAP.

Would anyone have an example that could share?

Thank you all in advance!

MZ

Hi Everyone!

I am new to DD. I am trying to declare and diagnose (with plots) a full factorial design (2x2x2, each arm has equal probability ) to include in the PAP.

Would anyone have an example that could share?

Thank you all in advance!

MZ

Hello

There’s an example of a 2x2x2 at https://declaredesign.org/library/articles/factorial.html - but it’s messy, lots of long estimands. You might want to write a few helper functions for dealing with some of the bookkeeping.

Hopefully that’s enough to get you started.

One way to to this is to make 8 potential outcomes, assign units to 8 conditions, then recode to the 3 factors – would this work for you?

```
library(DeclareDesign)
design <-
declare_population(N = 200) +
declare_potential_outcomes(Y_Z_T1 = rbinom(N, 1, 0.1),
Y_Z_T2 = rbinom(N, 1, 0.2),
Y_Z_T3 = rbinom(N, 1, 0.3),
Y_Z_T4 = rbinom(N, 1, 0.4),
Y_Z_T5 = rbinom(N, 1, 0.5),
Y_Z_T6 = rbinom(N, 1, 0.6),
Y_Z_T7 = rbinom(N, 1, 0.7),
Y_Z_T8 = rbinom(N, 1, 0.8)) +
declare_assignment(num_arms = 8) +
declare_reveal(Y, Z) +
declare_step(
Z1 = as.numeric(Z %in% c("T5", "T6", "T7", "T8")),
Z2 = as.numeric(Z %in% c("T3", "T4", "T7", "T8")),
Z3 = as.numeric(Z %in% c("T2", "T4", "T6", "T8")),
handler = fabricate
) +
declare_estimator(Y ~ Z1 + Z2 + Z3, term = TRUE, model = lm_robust)
run_design(design)
dat <- draw_data(design)
with(dat, table(Z1, Z2, Z3))
```

Dear Neal Fultz and Alex Coppock,

I would like to thank you both for your feedback.

@nfultz : I ended up using this code and added diagnostic, simulations and plot.

@Alex_Coppock: I found the code you share very intuitive however I was not able to understand the logic in the following step:

Z1 = as.numeric(Z %in% c(“T5”, “T6”, “T7”, “T8”)),

Z2 = as.numeric(Z %in% c(“T3”, “T4”, “T7”, “T8”)),

Z3 = as.numeric(Z %in% c(“T2”, “T4”, “T6”, “T8”)),

Could you briefly explain the logic behind the specific combination Ts?

Thanks!

Sure thing – we can express a 2 x2 x2 factorial as 8 levels of a single variable (Z) or as a specific combination of three variables (Z1, Z2, Z3). So that code is just a translation – Z1 is 1 for units in conditions 5, 6, 7,8 and 0 for the rest, etc etc.