This shows you the differences between two versions of the page.
r-permuted-block-randomization [2017/09/20 19:05] |
r-permuted-block-randomization [2017/09/20 19:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | The code below generates a permuted-block (block size is two) randomization of 200 participants to two arms in equal proportion, and plots the empirical proportion of participants in each arm as they are recruited. | ||
+ | <code> | ||
+ | interleave <- function(v1,v2) { | ||
+ | ord1 <- 2*(1:length(v1))-1 | ||
+ | ord2 <- 2*(1:length(v2)) | ||
+ | c(v1,v2)[order(c(ord1,ord2))] | ||
+ | } | ||
+ | x<-rbinom(100,1,0.5); | ||
+ | plot(cumsum(interleave(x,1-x))/(1:200), type='l', ylim=c(0,1)) | ||
+ | </code> |