User Tools

Site Tools


r-permuted-block-randomization

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.

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))
r-permuted-block-randomization.txt · Last modified: 2017/09/20 19:05 (external edit)