cluster_ra implements a random assignment procedure in which groups of units are assigned together (as a cluster) to treatment conditions. This function conducts complete random assignment at the cluster level, unless simple = TRUE, in which case simple_ra analogues are used.

cluster_ra(clusters = NULL, m = NULL, m_unit = NULL, m_each = NULL,
prob = NULL, prob_unit = NULL, prob_each = NULL, num_arms = NULL,
conditions = NULL, simple = FALSE, check_inputs = TRUE)

## Value

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

## Examples

# Two Group Designs
clusters <- rep(letters, times=1:26)

Z <- cluster_ra(clusters = clusters)
table(Z, clusters)
#>    clusters
#> 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  2  3  4  5  0  7  0  0 10  0 12  0 14 15  0 17 18  0  0 21 22  0  0  0
#>   1  1  0  0  0  0  6  0  8  9  0 11  0 13  0  0 16  0  0 19 20  0  0 23 24 25
#>    clusters
#> Z    z
#>   0  0
#>   1 26
Z <- cluster_ra(clusters = clusters, m = 13)
table(Z, clusters)
#>    clusters
#> 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  2  0  4  0  0  0  8  9 10  0 12  0  0  0  0  0 18 19 20  0  0 23  0 25
#>   1  0  0  3  0  5  6  7  0  0  0 11  0 13 14 15 16 17  0  0  0 21 22  0 24  0
#>    clusters
#> Z    z
#>   0 26
#>   1  0
Z <- cluster_ra(clusters = clusters, m_each = c(10, 16),
conditions = c("control", "treatment"))
table(Z, clusters)
#>            clusters
#> Z            a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v
#>   control    0  0  0  4  5  0  0  0  9  0  0  0  0  0  0 16  0 18 19  0 21 22
#>   treatment  1  2  3  0  0  6  7  8  0 10 11 12 13 14 15  0 17  0  0 20  0  0
#>            clusters
#> Z            w  x  y  z
#>   control    0 24 25  0
#>   treatment 23  0  0 26
# Multi-arm Designs
Z <- cluster_ra(clusters = clusters, num_arms = 3)
table(Z, clusters)
#>     clusters
#> 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  1  0  0  0  5  0  0  0  0  0  0 12  0  0 15  0 17  0 19 20 21  0 23  0  0
#>   T2  0  2  3  0  0  0  0  0  9  0  0  0  0 14  0 16  0 18  0  0  0 22  0 24  0
#>   T3  0  0  0  4  0  6  7  8  0 10 11  0 13  0  0  0  0  0  0  0  0  0  0  0 25
#>     clusters
#> Z     z
#>   T1  0
#>   T2 26
#>   T3  0
Z <- cluster_ra(clusters = clusters, m_each = c(7, 7, 12))
table(Z, clusters)
#>     clusters
#> 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  3  0  5  0  0  0  0  0  0  0 13  0 15  0  0  0 19  0  0  0 23 24  0
#>   T2  0  2  0  4  0  0  0  8  0  0  0 12  0  0  0  0  0  0  0  0 21  0  0  0 25
#>   T3  1  0  0  0  0  6  7  0  9 10 11  0  0 14  0 16 17 18  0 20  0 22  0  0  0
#>     clusters
#> Z     z
#>   T1  0
#>   T2 26
#>   T3  0
Z <- cluster_ra(clusters = clusters, m_each = c(7, 7, 12),
conditions = c("control", "placebo", "treatment"))
table(Z, clusters)
#>            clusters
#> Z            a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v
#>   control    0  0  0  4  0  6  0  8  0  0 11  0 13  0  0  0  0  0  0  0  0 22
#>   placebo    0  0  0  0  0  0  7  0  9  0  0  0  0  0 15  0  0  0  0 20  0  0
#>   treatment  1  2  3  0  5  0  0  0  0 10  0 12  0 14  0 16 17 18 19  0 21  0
#>            clusters
#> Z            w  x  y  z
#>   control   23  0  0  0
#>   placebo    0 24 25 26
#>   treatment  0  0  0  0
Z <- cluster_ra(clusters = clusters,
conditions = c("control", "placebo", "treatment"))
table(Z, clusters)
#>            clusters
#> Z            a  b  c  d  e  f  g  h  i  j  k  l  m  n  o  p  q  r  s  t  u  v
#>   control    0  0  0  0  0  6  7  8  9  0  0  0  0 14  0  0  0  0  0 20  0 22
#>   placebo    1  2  3  4  0  0  0  0  0  0 11  0 13  0  0  0  0  0  0  0  0  0
#>   treatment  0  0  0  0  5  0  0  0  0 10  0 12  0  0 15 16 17 18 19  0 21  0
#>            clusters
#> Z            w  x  y  z
#>   control    0  0 25 26
#>   placebo   23 24  0  0
#>   treatment  0  0  0  0