# How can I test this distribution?

Say I have 40 people that are sorted into 20 pairs. Out of the 40 people, 20 are A People and 20 are B People.

I want to see if the distribution of A People and B People is random. For example, if it were random, I would expect some pairs to have two A People and some to have two B People. If it were not random, I would expect most pairs to be one A Person and one B Person.

How can I test this? Also, would the test change if the 40 people were 10 A People and 30 B People?

This is for a personal project. Thank you!

• If it is for a personal project, please tell us how far you have gotten. And tag it self-study. Thx. – Peter Leopold Feb 12 '19 at 0:37
• I left the question general, but here is my real data: I have 62 people, 25 which are A People and 37 which are B People. I want to know if, in the 31 pairs, A People are non-randomly distributed. In the 31 pairs, 8 have 0 A People, 21 have 1 A Person, and 2 have 2 A People. – Ducon Feb 12 '19 at 0:38
• If random you would expect approximately 50% A and B, around 25% A and A and 25% B and B but nonrandom just means a large departure from these percentages. It does not necessarily mean almost all A and B. It would also be non random if almost none of the pairs were A and B as for example if half were A and A and the other half were B and B. – Michael R. Chernick Feb 12 '19 at 1:53
• In asking practical questions here, it is almost always a good idea to start by asking the exact problem at hand, instead of trying to pose a "generalized" problem – BruceET Feb 13 '19 at 18:39

Now that we have your actual question, I will try again to give a specific answer. Suppose we have 25 Type 1 people and 37 Type 2 people and put them at random into 31 pairs.

We choose 31 first members of each pair at random without replacement from among the 62; then we randomly choose 31 second members of each pair.

In R this can be done as follows:

set.seed(212)  # for reproducibility
pop = c(rep(1, 25), rep(2,37))
perm = sample(perm)  # randomly permute the 62 people
first = perm[1:31];  secnd = perm[32:62]
first; secnd
[1] 1 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 2 2 2 2 1 2 1 1 2 2 2 1
[1] 1 1 2 1 1 1 1 2 1 1 1 2 2 1 2 2 1 2 2 2 2 1 2 1 1 2 2 2 2 1 2


Then we count the pairs that have 1-1 or 2-2 matches. We see we have 18 matches out of 31 pairs. (It turns out that the number of matches is always even.)

sum(first==secnd)
[1] 18


Now we simulate this pairing and counting through a million iterations in order to approximate the distribution of the number of matches arising from random pairing.

set.seed(2019)
pop = c(rep(1, 25), rep(2,37));  m=10^6; x = numeric(m)
for(i in 1:m) {
perm = sample(pop)
x[i] = sum(perm[1:31]==perm[32:62]) }
table(x)/10^6
x
6        8       10       12       14       16       18
0.000173 0.003591 0.028495 0.110641 0.235683 0.291797 0.212950
20       22       24       26       28
0.091361 0.022099 0.003003 0.000202 0.000005


So it appears that we might reject the null hypothesis of independence at about the 6% level of significance, if we get 6, 8, 10, 22, 24, 26, 28 or 30 matches. (Or at about the 1% level if we get 6, 8, 24, 26, 28 or 30 matches.)

mean(abs(x-16) > 4)
[1] 0.057568
mean(abs(x-16) > 6)
[1] 0.006974


Notes: (1) A different simulation (with no specified seed or a different one) will give slightly different probabilities, but with a million iterations, probabilities should be accurate to two or three places. (2) You may want to try a combinatorial approach to finding the exact probabilities. (3) Although it didn't show up among a million iterations in the simulation shown, one could clearly get 30 matches as an extremely non-random possibility: 12 pairs with matching 1's and 18 with matching 2's, along with only one pair with a 1 and a 2.