# randomizr

block_ra implements a random assignment procedure in which units that are grouped into blocks defined by pre-treatment covariates are assigned using complete random assignment within block. For example, imagine that 50 of 100 men are assigned to treatment and 75 of 200 women are assigned to treatment.

```block_ra(blocks = NULL, prob = NULL, prob_each = NULL, m = NULL,
block_m = NULL, block_m_each = NULL, block_prob = NULL,
block_prob_each = NULL, num_arms = NULL, conditions = NULL,
check_inputs = TRUE)```

## Value

A vector of length N that indicates the treatment condition of each unit. Is numeric in a two-arm trial and a factor variable (ordered by conditions) in a multi-arm trial.

## Examples

```
# Two-arm Designs

blocks <- rep(c("A", "B","C"), times = c(50, 100, 200))
Z <- block_ra(blocks = blocks)
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  25  25
#>      B  50  50
#>      C 100 100
Z <- block_ra(blocks = blocks, prob = .3)
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  35  15
#>      B  70  30
#>      C 140  60
Z <- block_ra(blocks = blocks, block_prob = c(.1, .2, .3))
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  45   5
#>      B  80  20
#>      C 140  60
Z <- block_ra(blocks = blocks, m = 20)
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  30  20
#>      B  80  20
#>      C 180  20
Z <- block_ra(blocks = blocks, block_m = c(20, 30, 40))
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  30  20
#>      B  70  30
#>      C 160  40
block_m_each <- rbind(c(25, 25),
c(50, 50),
c(100, 100))

Z <- block_ra(blocks = blocks, block_m_each = block_m_each)
table(blocks, Z)#>       Z
#> blocks   0   1
#>      A  25  25
#>      B  50  50
#>      C 100 100
block_m_each <- rbind(c(10, 40),
c(30, 70),
c(50, 150))

Z <- block_ra(blocks = blocks, block_m_each = block_m_each,
conditions = c("control", "treatment"))
table(blocks, Z)#>       Z
#> blocks control treatment
#>      A      10        40
#>      B      30        70
#>      C      50       150
# Multi-arm Designs
Z <- block_ra(blocks = blocks, num_arms = 3)
table(blocks, Z)#>       Z
#> blocks T1 T2 T3
#>      A 17 16 17
#>      B 34 33 33
#>      C 67 66 67
block_m_each <- rbind(c(10, 20, 20),
c(30, 50, 20),
c(50, 75, 75))
Z <- block_ra(blocks = blocks, block_m_each = block_m_each)
table(blocks, Z)#>       Z
#> blocks T1 T2 T3
#>      A 10 20 20
#>      B 30 50 20
#>      C 50 75 75
Z <- block_ra(blocks = blocks, block_m_each = block_m_each,
conditions = c("control", "placebo", "treatment"))
table(blocks, Z)#>       Z
#> blocks control placebo treatment
#>      A      10      20        20
#>      B      30      50        20
#>      C      50      75        75
Z <- block_ra(blocks = blocks, prob_each = c(.1, .1, .8))
table(blocks, Z)#>       Z
#> blocks  T1  T2  T3
#>      A   5   5  40
#>      B  10  10  80
#>      C  20  20 160

```