blockrand {blockrand}R Documentation

Generate a block randomization for a clinical trial

Description

This function creates random assignments for clinical trials (or any experiment where the subjects come one at a time). The randomization is done within blocks so that the balance between treatments stays close to equal throughout the trial.

Usage

blockrand(n, num.levels = 2, levels = LETTERS[seq(length = num.levels)], id.prefix, stratum, block.sizes = 1:4, block.prefix)

Arguments

n The minimum number of subjects to randomize
num.levels The number of treatments or factor levels to randomize between
levels A character vector of labels for the different treatments or factor levels
id.prefix Optional integer or character string to prefix the id column values
stratum Optional character string specifying the stratum being generated
block.sizes Vector of integers specifying the sizes of blocks to use
block.prefix Optional integer or character string to prefix the block.id column

Details

This function will randomize subjects to the specified treatments within sequential blocks. The total number of randomizations may end up being more than n.

The final block sizes will actually be the product of num.levels and block.sizes (e.g. if there are 2 levels and the default block sizes are used (1:4) then the actual block sizes will be randomly chosen from the set (2,4,6,8)).

If id.prefix is not specified then the id column of the output will be a sequence of integers from 1 to the number of rows. If id.prefix is numeric then this number will be added to the set of integers. If id.prefix is a character string then the numbers will be converted to strings (zero padded) and have the prefix prepended.

The block.prefix will be treated in the same way as the id.prefix for identifying the blocks. The one difference being that the block.id will be converted to a factor in the final data frame.

For stratified studies the blockrand function should run once each for each stratum using the stratum argument to specify the current stratum (and using id.prefix and block.prefix to keep the id's unique). The separate data frames can then be combined using rbind if desired.

Value

A data frame with the following columns:

id: A unique identifier (number or character string) for each row
stratum: Optional, if stratum argument is specfied it will be replicated in this column
block.id: An identifier for each block of the randomization, this column will be a factor
block.size The size of each block
treatment The treatment assignment for each subject

Author(s)

Greg Snow greg.snow@intermountainmail.org

See Also

plot.blockrand, sample, rbind

Examples


## stratified by sex, 100 in stratum, 2 treatments
male <- blockrand(n=100, id.prefix='M', block.prefix='M',stratum='Male')
female <- blockrand(n=100, id.prefix='F', block.prefix='F',stratum='Female')

my.study <- rbind(male,female)

## Not run: 
plot.blockrand(my.study,'mystudy.pdf',
   top=list(text=c('My Study','Patient: %ID%','Treatment: %TREAT%'),
            col=c('black','black','red'),font=c(1,1,4)),
   middle=list(text=c("My Study","Sex: %STRAT%","Patient: %ID%"),
               col=c('black','blue','green'),font=c(1,2,3)),
   bottom="Call 123-4567 to report patient entry",
   cut.marks=TRUE)
## End(Not run)


[Package blockrand version 1.0 Index]