FAQ/secretS - CBU statistics Wiki

You can't save spelling words.

Clear message
location: FAQ / secretS

Bootstrap sampling without replacement - Secret Santa application

The below syntax randomly samples the numbers 1 to N without replacement. This sample will correspond to a random permutation of the numbers 1:N. This can be used to generate allocations for the Secret Santa. In this case a check, though, needs to be done to make sure that no number occupies the same position in the original and re-sampled data. The idea is that presents from people numbered 1:N in data x are given to those represented by the same numbers, in different positions, in data y.

In the below example N, the number of people in the Secret Santa, is taken as 44.

N <- 44
x <- c(1:N)
x <- matrix(x,N,1)
y <- sample(x)
y <- matrix(y,N,1)
z <- y-x

z computes the difference between the original and re-sampled data. If the differences are all non-zero then the numbers occupy different positions.

z
y
x
zz <- (z[,1]==0)
zz

Example output:

> x[,1]
 [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
[26] 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44


> y[,1]
 [1] 29  7 20 23 16 27 12 28 44 15 31 24 26 21 36  5 19 34 43 39 33 40 17 32  1
[26]  6 42 22 41  9 30  4 37 25 38 14  2 10  3  8 18 13 11 35


> zz
 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

There is also a website here which will also randomly allocate participants to recipients upon entry of their names in the 'Get Started' box.

For more general block randomization where groups of people are randomly allocated to a set number of blocks you can use on-line software here.

None: FAQ/secretS (last edited 2016-02-18 11:13:06 by PeterWatson)