A random assignment procedure in which units are assigned as clusters and clusters are nested within blocks.

block_and_cluster_ra(block_var, clust_var, prob = NULL, prob_each = NULL,
m = NULL, block_m = NULL, block_m_each = NULL, block_prob = NULL,
block_prob_each = NULL, num_arms = NULL, condition_names = NULL,
check_inputs = TRUE)

Value

A vector of length N that indicates the treatment condition of each unit.

Examples

clust_var <- rep(letters, times=1:26)

block_var <- rep(NA, length(clust_var))
block_var[clust_var %in% letters[1:5]] <- "block_1"
block_var[clust_var %in% letters[6:10]] <- "block_2"
block_var[clust_var %in% letters[11:15]] <- "block_3"
block_var[clust_var %in% letters[16:20]] <- "block_4"
block_var[clust_var %in% letters[21:26]] <- "block_5"

table(block_var, clust_var)#>          clust_var
#> block_var  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w
#>   block_1  1  2  3  4  5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0
#>   block_2  0  0  0  0  0  6  7  8  9 10  0  0  0  0  0  0  0  0  0  0  0  0  0
#>   block_3  0  0  0  0  0  0  0  0  0  0 11 12 13 14 15  0  0  0  0  0  0  0  0
#>   block_4  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 16 17 18 19 20  0  0  0
#>   block_5  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0 21 22 23
#>          clust_var
#> block_var  x  y  z
#>   block_1  0  0  0
#>   block_2  0  0  0
#>   block_3  0  0  0
#>   block_4  0  0  0
#>   block_5 24 25 26
Z <- block_and_cluster_ra(block_var = block_var,
clust_var = clust_var)

table(Z, block_var)#>    block_var
#> Z   block_1 block_2 block_3 block_4 block_5
#>   0       8      16      24      37      72
#>   1       7      24      41      53      69table(Z, clust_var)#>    clust_var
#> Z    a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y
#>   0  0  0  3  0  5  6  0  0  0 10 11  0 13  0  0  0 17  0  0 20  0  0 23 24 25
#>   1  1  2  0  4  0  0  7  8  9  0  0 12  0 14 15 16  0 18 19  0 21 22  0  0  0
#>    clust_var
#> Z    z
#>   0  0
#>   1 26
Z <- block_and_cluster_ra(block_var = block_var,
clust_var = clust_var,
num_arms = 3)

table(Z, block_var)#>     block_var
#> Z    block_1 block_2 block_3 block_4 block_5
#>   T1       4      19      26      19      43
#>   T2       9      14      26      55      49
#>   T3       2       7      13      16      49table(Z, clust_var)#>     clust_var
#> Z     a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y
#>   T1  0  0  0  4  0  0  0  0  9 10  0 12  0 14  0  0  0  0 19  0 21 22  0  0  0
#>   T2  1  0  3  0  5  6  0  8  0  0 11  0  0  0 15  0 17 18  0 20  0  0 23  0  0
#>   T3  0  2  0  0  0  0  7  0  0  0  0  0 13  0  0 16  0  0  0  0  0  0  0 24 25
#>     clust_var
#> Z     z
#>   T1  0
#>   T2 26
#>   T3  0
Z <- block_and_cluster_ra(block_var = block_var,
clust_var = clust_var,
prob_each = c(.2, .5, .3))

block_m_each <- rbind(c(2, 3),
c(1, 4),
c(3, 2),
c(2, 3),
c(5, 1))

Z <- block_and_cluster_ra(block_var = block_var,
clust_var = clust_var,
block_m_each = block_m_each)

table(Z, block_var)#>    block_var
#> Z   block_1 block_2 block_3 block_4 block_5
#>   0       5       9      40      37     118
#>   1      10      31      25      53      23table(Z, clust_var)#>    clust_var
#> Z    a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v  w  x  y
#>   0  1  0  0  4  0  0  0  0  9  0  0 12 13  0 15  0  0 18 19  0 21 22  0 24 25
#>   1  0  2  3  0  5  6  7  8  0 10 11  0  0 14  0 16 17  0  0 20  0  0 23  0  0
#>    clust_var
#> Z    z
#>   0 26
#>   1  0