Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Randomize directly to condition in a factorial experiment

    Hello,

    Does Stata have the capability to randomize participants to 1 of 32 conditions in a 2x2x2x2x2 factorial experiment? I have a conditions table (1....32 for 5 factors, each two levels) and want to stratify directly to condition versus combination of factors, as outlined in ralloc. I am using a full factorial design, under guidance from the Multiphase Optimization Strategy: https://publichealth.nyu.edu/w/ioi/o...tions/overview

    Guidance on generating the allocation table using R is provided here: https://publichealth.nyu.edu/w/ioi/r...al-redcap-most

    And this is the code for R they provide in the example for a full factorial trial with 8 conditions (2x2x2)

    library(tidyverse)
    DF <- expand.grid(Person = 1:800, scr1_gender = 1:2)
    DF <- DF %>% mutate(Block = cut(Person, 100))
    set.seed(732212)
    DF <- DF %>%
    group_by(scr1_gender, Block) %>%
    mutate(rand_scond = sample(3:10)) %>%
    ungroup()
    write.table(DF %>% select(rand_scond, scr1_gender), file = "atab.csv", row.names = FALSE, sep = ",")


    Note: I am not stratifying on any variables. So, is there a way to use ralloc to directly randomize to condition or can you provide guidance on using factor with ralloc for a 2x2x2x2x2?

    Many thanks,
    Heather


  • #2
    The user written program -ralloc- (available on SSC) does not support a 2x2x2x2x2 factorial design. As it currently stands, the most complex factorial study it supports is a 3x3x3 design. I have no plans to enhance -ralloc-. I think you will need to source other software or perhaps program something up yourself. Good luck with your experiment.

    Comment


    • #3
      Here's a suggested approach (example code below) if you're going to program it yourself.

      The example does a permuted block randomization (fixed block size) with a sample size of 10 participants per condition. But you can adapt it for your sample size or other block sizes.

      (I think that, with thirty-two treatment conditions, you probably don't need to to block randomization at all.)
      Code:
      version 17.0
      
      clear *
      
      // seedem
      set seed 1422517637
      
      /* 32 treatment conditions Ă— 10 participants per condition,
         fixed block size of 64 (2 of each condition per block) */
      local trt_tally 32
      local sample_size 10
      local block_size = 2 * 32 // Five blocks of 64 participants each
      local block_tally = `trt_tally' * `sample_size' / `block_size'
      
      quietly set obs `= `trt_tally' * `sample_size''
      
      generate byte trt = mod(_n, `trt_tally') + 1
      bysort trt: generate byte blk = mod(_n, `block_tally') + 1
      
      // Random allocation
      generate double randu = runiform()
      isid randu
      
      // Participant IDs ("001", "002", . . ., "320", i.e., enrollment accession numbers)
      sort blk randu
      generate str pid = string(_n, "%03.0f")
      
      /* Factors for treatment identification—Completely randomized
         factorial (2 x 2 x 2 x 2 x 2 ) design */
      frame create Factors
      frame Factors {
          
          quietly set obs 2
          generate byte fac1 = mod(_n, 2)
      
          forvalues factor = 2/5 {
              quietly expand 2
              bysort _all: generate byte fac`factor' = mod(_n, 2)
          }
      
          quietly isid _all, sort
          generate byte trt = _n
      }
      quietly frlink m:1 trt, frame(Factors)
      quietly frget fac?, from(Factors)
      
      /* Done */
      quietly export delimited pid trt fac? using randomization_list.csv, quote
      
      // Verification (sanity check)
      contract blk fac?, freq(trt_per_block)
      assert trt_per_block == `block_size' / `trt_tally'
      
      contract blk, freq(trt_tally)
      assert _N == `block_tally'
      assert trt_tally == `trt_tally'
      
      exit
      Attached Files

      Comment

      Working...
      X