Learn R Programming

simtrial (version 1.0.0)

randomize_by_fixed_block: 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))

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.

Arguments

n

Sample size to be randomized.

block

Vector of treatments to be included in each block.

Examples

Run this code
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())

Run the code above in your browser using DataLab