Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Generate a restricted randomization between two groups, with a bias towards maintaining approximately equal allocation
ResourceFunction["EfronBiasedCoin"][p,n] generates a sequence of n restricted randomizations between two groups, maintaining approximately equal allocation with bias p. |
Generate a sequence of 100 options with a bias of (p = 2/3) towards equal allocation:
In[1]:= |
Out[1]= |
Different weighting can be given to the restriction of equal allocation:
In[2]:= |
Out[2]= |
In[3]:= |
Out[3]= |
In[4]:= |
Out[4]= |
Different sequence lengths can be generated:
In[5]:= |
Out[5]= |
In[6]:= |
Out[6]= |
In[7]:= |
Out[7]= |
Users may replace the default symbols for the groups in any way they like:
In[8]:= |
Out[8]= |
Find the count of all values that follow an "A” when p is near 1/2:
In[9]:= |
Out[10]= |
Compare to when p is near 1. This shows a strong bias for alternating:
In[11]:= |
Out[12]= |
Complete randomization is achieved by a (p = 1/2) weighting towards selection of the underrepresented group:
In[13]:= |
Out[13]= |
Complete randomization (p = 1/2) is thus equivalent to simple utilization of RandomChoice, albeit with the sequentially biased algorithm being slower:
In[14]:= |
Out[16]= |
In[17]:= |
Out[17]= |
In[18]:= |
Out[19]= |
The variance in allocation percentage for a given group can be diminished by weighting the randomization scheme (p ≠ 1/2):
In[20]:= |
Out[21]= |
In[22]:= |
Out[22]= |
In[23]:= |
Out[24]= |
Explore the options in variance of allocation percentage as a function of the bias p:
In[25]:= |
Out[26]= |
In[27]:= |
Out[27]= |
This work is licensed under a Creative Commons Attribution 4.0 International License