http://cged.genes.nig.ac.jp/RGM2/pkg.php?p=blockrand blockrand
R add-on package.
#---------------------------------------------------------------------
# Second example: # --> generate lists for 6 sites # --> N = 100 per site # --> 3 treatment arms (A, B, C) # --> blocks of size 3 and 6 # * Generate a list that is at least 600 elements long * b <- 136 # number of blocks s <- c(3,6) # number of subjects per block set.seed(1) # so can reproduce results m <- sample(s, b, replace=T) # actual number of subjects over blocks # Get treatment assignments for each block, randomized within blocks # --> i.e. randomized permuted block list treats <- vector('list', b) for(i in 1:b) treatsI <- sample(c(rep('A',m[i]/3), rep('B',m[i]/3), rep('C', m[i]/3))) treats # print for statistician use unlist(treats) # print blinded to block boundaries # Check the length of treats --- Need 600 total elements length(unlist(treats)) # Check the randomization using table: table(unlist(treats)) # NOTE: the above lists is 603 elements long, but we only need the # first 600 elements # NOTE: the treatments are no longer equally distributed # among the 600 patients table(unlist(treats)[1:600]) # Create list as dataframe x<-data.frame(id=1:600, treatment=unlist(treats)[1:600]) write.table(x, "randlists.csv", sep=",", row.names=FALSE, quote=FALSE)