0
$\begingroup$

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!

New contributor
Ducon is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
$\endgroup$
  • $\begingroup$ If it is for a personal project, please tell us how far you have gotten. And tag it self-study. Thx. $\endgroup$ – Peter Leopold Feb 12 at 0:37
  • 1
    $\begingroup$ 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. $\endgroup$ – Ducon Feb 12 at 0:38
  • 1
    $\begingroup$ 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. $\endgroup$ – Michael Chernick Feb 12 at 1:53
  • $\begingroup$ 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 $\endgroup$ – BruceET Feb 13 at 18:39
1
$\begingroup$

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 

enter image description here

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.

$\endgroup$

Your Answer

Ducon is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.