id | stratum | block.id | block.size | treatment |
---|---|---|---|---|
No data |
Single value, integer or null
The minimum number of subjects to randomize
The number of treatments or factor levels to randomize between
A character vector of labels for the different treatments or factor levels
Optional integer or character string to prefix the id column values
Optional character string specifying the stratum being generated
Vector of integers specifying the sizes of blocks to use
Optional integer or character string to prefix the block.id column
This website implements randomization based on R language, in the blockrand(v1.5) package of R language. This feature creates random assignments for clinical trials (or any experiment that only accepts one subject at a time). Randomization is completed within the block to maintain a close to equal balance between treatments throughout the entire trial process.
The so-called random number is actually a "pseudo-random number", which is obtained by iterating forward from a set of starting values (called seeds) using a certain recursive calculation method. So starting from the same seed, the sequence of random numbers obtained is the same.
blockrand(n, num.levels = 2, levels = LETTERS[seq(length = num.levels)], id.prefix,
stratum, block.sizes = 1:4, block.prefix, uneq.beg=FALSE, uneq.mid=FALSE, uneq.min=0,
uneq.maxit=10)
【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
【uneq.beg】:Should an unequal block be used at the beginning of the randomization
【uneq.mid】:Should an unequal block be used in the middle
【uneq.min】:what is the minimum difference between the most and least common levels in an unequal block
【uneq.maxit】:maximum number of tries to get uneq.min difference
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
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 the id column of the output will be a sequence of integers starting at the value of id.prefix. 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.
If uneq.beg and/or uneq.mid are true then an additional block will be used at the beginning and/or inserted in the middle that is not balanced, this means that the final totals in each group may not be exactly equal (but still similar). This makes it more difficult to anticipate future assignments as the numbers will not return to equality at the end of each block.
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.
Schulz, K. and Grimes, D. (2002): Unequal group sizes in randomized trials: guarding against guessing, The Lancet, 359, pp 966--970.
https://www.rdocumentation.org/packages/simEd/versions/2.0.1/topics/set.seed
https://www.rdocumentation.org/packages/blockrand/versions/1.5/topics/blockrand
plotblockrand, sample, rbind
# NOT RUN {
## 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 {
plotblockrand(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)
# }
# NOT RUN {
# }