I know I can use complete_ra from the randomizr package to randomly and equally allocate to one of three "arms" (in this case "arms" are just names of people)
library(randomizr)
set.seed(100)
names <- complete_ra(N = 500, num_arms = 3)
#each "arm" is chosen ~167 times
#Now put the names in
library(plyr)
df <- transform(df,
names=revalue(names,c("T1"="Luis", "T2"="Conor","T3"="Dafydd")))
But what I need is to actually assign the 500 samples to a randomly chosen two of the three names. So I need my dataset to be:
ID# Name1 Name2
1 Conor Luis
2 Conor Dafydd
3 Luis Dafydd
...
500 Conor Luis
and at the end I need each of the 3 to still be chosen an equal amount.
A workaround is since there's 3 names, that means there's 3 combinations too, so I could simply replace Conor with "Conor and Luis", Luis with "Luis and Dafydd", and Dafydd with "Conor and Dafydd"...but I'm sure there's a more eloquent way that would allow for other combinations (like choosing 2 out of 4 names). Also I don't like the workaround because currently each name can show up 8 times in a row for example, which means we would have an exact pair 8 times in a row. I think a more eloquent method of randomly choosing 2 out of the 3 names would result in fewer "in a row" cases.
Aucun commentaire:
Enregistrer un commentaire