For many studies, enrollment is on-going. However, the same problems associated with random assignment as with any study is that randomization does not always randomize (e.g. one intervention could have significantly more women than men). Therefore, one common approach is to stratify on key variables (e.g. gender, race).
The blockrand package is designed for this kind of study.
First, we want to library (install if you have not already) the blockrand package.
library(blockrand)
For this example, we are assuming about 20 people will be enrolled and we think that gender (male and female) is critical to ensure that they are equally spread throughout the different treatments, which in our case we are using A (treatment) and B (control) groups. The code below from the blockrand guide demonstrates how to produce this random sequence.
male = blockrand(n = 10, id.prefix = "M", block.prefix = "M", stratum = "Male")
female = blockrand(n = 10, id.prefix = "M", block.prefix = "M", stratum = "Female")
random_assign = rbind(male, female)
random_assign
## id stratum block.id block.size treatment
## 1 M01 Male M1 6 B
## 2 M02 Male M1 6 A
## 3 M03 Male M1 6 A
## 4 M04 Male M1 6 A
## 5 M05 Male M1 6 B
## 6 M06 Male M1 6 B
## 7 M07 Male M2 4 B
## 8 M08 Male M2 4 A
## 9 M09 Male M2 4 B
## 10 M10 Male M2 4 A
## 11 M01 Female M1 8 A
## 12 M02 Female M1 8 A
## 13 M03 Female M1 8 A
## 14 M04 Female M1 8 B
## 15 M05 Female M1 8 B
## 16 M06 Female M1 8 A
## 17 M07 Female M1 8 B
## 18 M08 Female M1 8 B
## 19 M09 Female M2 4 A
## 20 M10 Female M2 4 A
## 21 M11 Female M2 4 B
## 22 M12 Female M2 4 B
With this data, a researcher can split this information into a spreadsheet and when a male comes in they can look at the male spreadsheet and see which treatment package this person will get. Or the researcher can just provide a set of envelopes that is in two piles male and female that has the treatment assignment and the researcher could just hand the treatment assignment to the participant.