Number of random samples with N unique values

42 Views Asked by At

I've asked 20 people to rank 6 objects in order from best to worst. From these 20 rankings there are 13 unique types (e.g. 7 people choose the order [1,2,3,4,5,6], and everybody else chooses a different, unique order). What is the probability of observing N=13 unique types given random rankings?

The number of possible ranking orders is:

perm <- function(n,k){choose(n,k) * factorial(k)}
numRanks = perm(6,6)
numRanks
720

So there are 720 ways that 20 people can choose the same ranking (right?).

Let's say we want to find out how many ways that 20 people can choose 2 unique rankings. There are choose(720, 2) combinations of pairs of ranks, and perm(20,2) permutations for each pair to be chosen by the 20 people. Some of these permutations only have 1 unique ranking, not 2, so we need to take away 2 (all ranking order A or all ranking order B). The number we need to subtract is the factorial of target number of unique ranks (???). So we have something like:

numPeople = 20

getNumberOfWaysOfMakingNUniqueRanks = function(numPeople,numRanks,numUniqueRanks){
  choose(numRanks,numUniqueRanks) * (perm(numPeople,numUniqueRanks)-factorial(numUniqueRanks))
}

numberOfWaysOfMakingNUniqueRanks = 
  sapply(1:20, function(X){
    numberOfWaysOfMakingNUniqueRanks(numPeople,numRanks,X)
})

The number of ways of choosing N unique ranks:

 [1] 1.368000e+04 9.784152e+07 4.233597e+11
 [4] 1.290949e+15 2.958242e+18 5.288063e+21
 [7] 7.551451e+24 8.749344e+27 8.306060e+30
[10] 6.496173e+33 4.192982e+36 2.229614e+39
[13] 9.714208e+41 3.433928e+44 9.697038e+46
[16] 2.136075e+49 3.535972e+51 4.124794e+53
[19] 2.910926e+55 0.000000e+00

But that's not right - the 1st number should be 720, and there should be more than 0 ways when N=20. What am I doing wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

Note : This is not the solution but hopefully it can help when you formulate the code.

Let X be the number of unique elements

Total cases = 720

For X=1 we can choose $\binom{720}{1}$

There is only one way where we can have one unique element when all 20 people chooses the same ranking

Total = 720*1= 720

For X=2 we can choose $\binom{720}{2}$

No of ways 20 people can choose 2 unique elements are (1,19)(2,18)(3,17)......(19,1) where distribution is given by (1,19)=$\frac{20!}{1!19!}$;(2,18)=$\frac{20!}{2!18!}$;.........(19,1)=$\frac{20!}{19!1!}$;

Lets say $N_2$ is the summation of all these cases

Final result = $\binom{720}{2}$*$N_2$

The alternate way to calculate X=2 is the above term is the binomial expansion of $(x+y)^n$ where n = 20 minus the cases which are (20,0)(0,20) = $2^n$-2

Similarly For X = 3 we have $(x+y+z)^n$ minus cases Such as (20,0,0)(17,3,0).... etc

.. For X= 20

you can either do with the binomial expansion and find out the cases or alternatively you can see that there is only one way when every single person gets the unique pattern and such arrangements can be given by 20!

Total =$\binom{720}{20}*20!$