randomize_by_fixed_block: Permuted fixed block randomization

View source: R/randomize_by_fixed_block.R

randomize_by_fixed_blockR 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"
tibble(x = 1:10) %>% mutate(Treatment = randomize_by_fixed_block(block = c("A", "B", "B")))

# example 2
# Stratified randomization
tibble(Stratum = c(rep("A", 10), rep("B", 10))) %>%
  group_by(Stratum) %>%
  mutate(Treatment = randomize_by_fixed_block())


keaven/simtrial documentation built on April 17, 2023, 4:03 a.m.