randomize_by_fixed_block {simtrial} | R Documentation |
Permuted fixed block randomization
Description
Fixed block randomization. The block
input should repeat each
treatment code the number of times it is to be included within each block.
The final block will be a partial block if n
is not an exact multiple
of the block length.
Usage
randomize_by_fixed_block(n = 10, block = c(0, 0, 1, 1))
Arguments
n |
Sample size to be randomized. |
block |
Vector of treatments to be included in each block. |
Value
A treatment group sequence (vector) of length n
with
treatments from block
permuted within each block having
block size equal to the length of block
.
Examples
library(dplyr)
# Example 1
# 2:1 randomization with block size 3, treatments "A" and "B"
data.frame(x = 1:10) |> mutate(Treatment = randomize_by_fixed_block(block = c("A", "B", "B")))
# Example 2
# Stratified randomization
data.frame(stratum = c(rep("A", 10), rep("B", 10))) |>
group_by(stratum) |>
mutate(Treatment = randomize_by_fixed_block())
[Package simtrial version 0.4.1 Index]