Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Problem
Dave’s Donuts offers 14 flavors of donuts (consider the supply of each flavor as being unlimited). The “grab bag” box consists of flavors randomly selected to be in the box, each flavor equally likely for each one of the dozen donuts. What is the probability that at most three flavors are in the grab bag box of a dozen?
< !---more-->
Solution
For this we will need the multinomial distribution, which is a discrete probability distribution. In a string of characters there are
< !-- MATH \begin{displaymath}\Prob{X_1=x_1,\ldots,X_{k}=x_{k}} =\frac{n!}{x_1!\ldots x_{k}!}p_1^{x_1}\ldots p_{k}^{x_{k}}.\end{displaymath} -->
Here,
We will say
Compute each of those probabilities separately.
If
Let’s now compute < !-- MATH $\Prob{\text{Exactly two flavors}}$ -->
Unfortunately (2) includes cases where there’s actually 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 < !-- MATH $\binom{14}{2}$ -->
Now to compute < !-- MATH $\Prob{\text{Exactly three flavors}}$ -->
We could try and use tricks to compute (6) or we can acknowledge that we’re busy people and ask SymPy to do it. Check that the following Python code is correct:
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 < !-- MATH $\frac{129789}{14173478093824}$ -->
We can write (1) and (5) as < !-- MATH $\frac{1}{4049565169664}$ -->
Related Question
This is the proper way to obtain the probability that there are at most three flavors in the “grab bag” box, but how many boxes exist in which there are at most three flavors when we discount the number of ways there are to arrange the donuts in a box?
If there’s exactly one flavor, then we pick it and fill the box with that flavor; there’s 14 ways to pick one flavor. If there’s exactly two flavors in the box, we’ll call them Flavor 1 and Flavor 2. There is at least one donut of Flavor 1 and one of Flavor 2. Now pick the rest of the donuts’ flavors, order doesn’t matter, there is replacement; there are < !-- MATH $\binom{10 + 2 - 1}{10} =\binom{11}{10} = 11$ -->
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)!
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.