What is the probability that in a box of a dozen donuts picked from 14 flavors there’s no more than 3 flavors in the box?
This article is originally published at https://ntguardian.wordpress.com
Problem
Dave’s Donuts offers 14 flavors of donuts (consider the supply of eachflavor as being unlimited). The “grab bag” box consists of flavorsrandomly selected to be in the box, each flavor equally likely for eachone of the dozen donuts. What is the probability that at most three flavors arein the grab bag box of a dozen?
Solution
For this we will need the multinomial distribution, which is a discreteprobability distribution. In a string of characters there are characterspossible to fill one position of the string, which is
characters long. Therandom variable
counts the number of occurences of character 1 in thestring,
the number of occurences of character 2, and so on until
.Let
be the individual probability each of the characterscould appear in a position of the string; each position is filled independentlyof the characters in other positions. Let
such that
. Then

Here, ,
, and
. So we can say
We will say
![]() | ![]() | |
![]() | ||
![]() |
Compute each of those probabilities separately.
If and
, there is exactly one flavor in the box.(1) shows the probability this happens is
. Sincewe could pick an
and there were 14 ways to make this decision, we cansay
Let’s now compute . We start by fixing
. We get
Unfortunately (2) includes cases where there’sactually only one flavor present in the box, so compute
![]() | ![]() | (3) |
![]() | (4) |
Of course we could have picked different variables to fix at zero, andthere were ways to pick the variables to fix at zero (orequivalently, pick the variables to not fix at zero), finally yielding
Now to compute . Again we start by fixing
and compute
We could try and use tricks to compute (6) or we can acknowledge that we’rebusy people and ask SymPy to do it. Check that the following Python code iscorrect:
from sympy import init_session, binomial init_session() def multinomial(params): if len(params) == 1: return 1 return binomial(sum(params), params[-1]) * \ multinomial(params[:-1]) l1 = list() for i in range(1, 10 + 1): v = sum([multinomial([i, j, (12 - i - j)]) for j in range(1, 11 - i + 1)]) l1.append(v) sum(l1)/14**12 # Solution
The resulting probability is . We could havepicked different flavors to fix, and there were
ways to pickthe flavors to fix, so we get
We can write (1) and (5) as and
, respectively.Summing these probabilities yields
Related Question
This is the proper way to obtain the probability that there are at most threeflavors in the “grab bag” box, but how many boxes exist in which there are atmost three flavors when we discount the number of ways there are to arrange thedonuts in a box?
If there’s exactly one flavor, then we pick it and fill the box with thatflavor; there’s 14 ways to pick one flavor. If there’s exactly two flavors inthe box, we’ll call them Flavor 1 and Flavor 2. There is at least one donut ofFlavor 1 and one of Flavor 2. Now pick the rest of the donuts’ flavors, orderdoesn’t matter, there is replacement; there are ways to do that. Then pick the two flavors: there’s
ways to do that, and thus
boxes with exactly twoflavors. Similarly, for exactly three flavors, there are
ways for there to be exactlythree flavors. Sum these numbers. (See https://math.stackexchange.com/q/3230011.) There are 21,035 such boxes.
Special thanks to Math Stack Exchange user wavex for his help with this problem! He provided the following R script for simulating it:
total = 0 for (y in 1:10000000){ x = rmultinom(1,12,c(1/14,1/14,1/14,1/14,1/14, 1/14,1/14,1/14,1/14,1/14,1/14,1/14,1/14,1/14)) x <- c(x) count = 14 for(i in x){ if(i==0){ count = count -1 } } if(count <= 3){total = total + 1} } sprintf("%.20f", total / 10000000)
In his run of the code this event occured only 27 out of 10,000,000 times. A rare event indeed!
About this document …
This document was generated using the LaTeX2HTML translator Version 2019 (Released January 1, 2019)
The command line arguments were:
latex2html -split 0 -nonavigation -lcase_tags -image_type gif Example6Solution.tex
The translation was initiated on 2019-05-20
Packt Publishing published a book for me entitled Hands-On Data Analysis with NumPy and Pandas, a book based on my video course Unpacking NumPy and Pandas. This book covers the basics of setting up a Python environment for data analysis with Anaconda, using Jupyter notebooks, and using NumPy and pandas. If you are starting out using Python for data analysis or know someone who is, please consider buying my book or at least spreading the word about it. You can buy the book directly or purchase a subscription to Mapt and read it there.
If you like my blog and would like to support it, spread the word (if not get a copy yourself)!
Thanks for visiting r-craft.org
This article is originally published at https://ntguardian.wordpress.com
Please visit source website for post related comments.