ransch: ransch

View source: R/stat.R

ranschR Documentation

ransch

Description

Generate block randomization schedule tables with fixed or random block size.

Usage

ransch(n, block, arms, r = rep_len(1L, length(arms)), strata = NULL)

ranschtbl(
  n,
  block,
  arms,
  r = rep_len(1L, length(arms)),
  strata = NULL,
  write = NULL
)

Arguments

n

sample size of study or each stratum

block

block size; note if block is not a factor of n, n will be increased to accommodate a full block

for randomly-sized blocks, a vector of potential block sizes; note that a block size must be a multiple of sum(r)

arms

names of the treatment arms

r

randomization ratio; see examples

strata

an optional named list of vectors for each stratum

write

a file path to write a directory with csv files for each randomization table

Examples

## no strata, 2-3 treatments with varying randomization ratios
ransch(24, 4, 1:2) ## 1:1
ransch(24, 6, 1:3) ## 1:1:1
ransch(24, 8, 1:3, c(1, 2, 1)) ## 1:2:1


## randomly-sized blocks
ransch(24, c(2, 4, 6), 1:2)

set.seed(1)
r1 <- ransch(24, c(3, 6, 9), 1:3)
set.seed(1)
r2 <- ransch(24, 1:10, 1:3)

## note that these two are the same since only blocks sized 3, 6, 9
## work for 1:1:1 randomization
identical(r1, r2)
addmargins(table(r1[[1]][, -1]))


## one two-level stratum
ransch(24, 4, 1:2, strata = list(Age = c('<65', '>=65')))

## multiple strata
strata <- list(Site = LETTERS[1:3], Age = c('<65', '>=65'))
ransch(24, 4, 1:2, strata = strata)


## tables for printing
ranschtbl(24, 4, c('Pbo', 'Trt'))
ranschtbl(24, 4, c('Pbo', 'Trt'), c(1, 3), strata)

## Not run: 
ranschtbl(24, 4, c('Pbo', 'Trt'), strata = strata, write = '~/desktop')

## End(Not run)


raredd/rawr documentation built on April 29, 2024, 10:29 a.m.