Skip to contents

Generate a randomization list for a single stratum with blocks of varying sizes.

Usage

blockrand(n, arms = LETTERS[seq(2)], blocksizes = 1:4, pascal = TRUE)

Arguments

n

total number of randomizations (within a single stratum)

arms

number of arms to randomise

blocksizes

numbers of each arm to include in blocks

pascal

logical, whether to use pascal's triangle to determine block sizes

Value

a data frame with columns block, blocksize, seq_in_block, arm

Details

By default, frequency of the different block sizes is determined using Pascal's triangle. This has the advantage that small and large block sizes are less common than intermediate sized blocks, which helps with making it more difficult to guess future allocations, and reduces the risk of finishing in the middle of a large block.

Unbalanced randomization is possible by specifying the same arm label multiple times.

Examples

set.seed(1)
blockrand(10)
#>    seq_in_list block blocksize seq_in_block arm
#> 1            1     1         4            1   A
#> 2            2     1         4            2   B
#> 3            3     1         4            3   B
#> 4            4     1         4            4   A
#> 5            5     2         4            1   A
#> 6            6     2         4            2   B
#> 7            7     2         4            3   A
#> 8            8     2         4            4   B
#> 9            9     3         6            1   B
#> 10          10     3         6            2   B
#> 11          11     3         6            3   A
#> 12          12     3         6            4   B
#> 13          13     3         6            5   A
#> 14          14     3         6            6   A

# different arm labels
blockrand(10, arms = c("Arm 1", "Arm 2"))
#>    seq_in_list block blocksize seq_in_block   arm
#> 1            1     1         8            1 Arm 1
#> 2            2     1         8            2 Arm 2
#> 3            3     1         8            3 Arm 2
#> 4            4     1         8            4 Arm 2
#> 5            5     1         8            5 Arm 2
#> 6            6     1         8            6 Arm 1
#> 7            7     1         8            7 Arm 1
#> 8            8     1         8            8 Arm 1
#> 9            9     2         2            1 Arm 1
#> 10          10     2         2            2 Arm 2

# block sizes 2, 4, and 6, 2 arms
blockrand(20, blocksizes = 1:3)
#>    seq_in_list block blocksize seq_in_block arm
#> 1            1     1         2            1   B
#> 2            2     1         2            2   A
#> 3            3     2         6            1   A
#> 4            4     2         6            2   B
#> 5            5     2         6            3   A
#> 6            6     2         6            4   A
#> 7            7     2         6            5   B
#> 8            8     2         6            6   B
#> 9            9     3         2            1   B
#> 10          10     3         2            2   A
#> 11          11     4         4            1   A
#> 12          12     4         4            2   B
#> 13          13     4         4            3   A
#> 14          14     4         4            4   B
#> 15          15     5         6            1   A
#> 16          16     5         6            2   A
#> 17          17     5         6            3   B
#> 18          18     5         6            4   B
#> 19          19     5         6            5   B
#> 20          20     5         6            6   A

# unbalanced randomisation (2:1)
blockrand(12, arms = c("Arm 1", "Arm 1", "Arm 2"))
#>    seq_in_list block blocksize seq_in_block   arm
#> 1            1     1         6            1 Arm 2
#> 2            2     1         6            2 Arm 1
#> 3            3     1         6            3 Arm 1
#> 4            4     1         6            4 Arm 1
#> 5            5     1         6            5 Arm 1
#> 6            6     1         6            6 Arm 2
#> 7            7     2         9            1 Arm 2
#> 8            8     2         9            2 Arm 2
#> 9            9     2         9            3 Arm 1
#> 10          10     2         9            4 Arm 1
#> 11          11     2         9            5 Arm 1
#> 12          12     2         9            6 Arm 1
#> 13          13     2         9            7 Arm 2
#> 14          14     2         9            8 Arm 1
#> 15          15     2         9            9 Arm 1

# fixed block sizes
blockrand(10, blocksizes = 2)
#>    seq_in_list block blocksize seq_in_block arm
#> 1            1     1         4            1   B
#> 2            2     1         4            2   A
#> 3            3     1         4            3   B
#> 4            4     1         4            4   A
#> 5            5     2         4            1   B
#> 6            6     2         4            2   B
#> 7            7     2         4            3   A
#> 8            8     2         4            4   A
#> 9            9     3         4            1   B
#> 10          10     3         4            2   A
#> 11          11     3         4            3   A
#> 12          12     3         4            4   B