# Bayes' Rule with Binomial Random Variable

I am working on this problem:

Suppose that when a machine is adjusted properly, $50$% of the items produced by it are of high quality and the other $50$% are of medium quality. Suppose, however, that the machine is improperly adjusted during 10% of the time and that, under these conditions, $25$% of the items produced by it are of high quality and $75$% are of medium quality.

Suppose that $5$ items produced by the machine at a certain time are selected at random and inspected. If 4 of these items are of high quality and 1 item is of medium quality, what is the probability that the machine was adjusted properly at that time?

It seems to me that the question in the 2nd part is referring to a binomial random variable, so I called it H and found that:

$P(H=4|5, 0.5)$ = $0.15625$

$P(H=4|5, 0.25)$ = $0.01465$

After that it seems the logical thing to do would be to apply Bayes' rule to the first probability to find:

$P(\text{properly adjusted} \mid H=4)$ = $0.15625*P(\text{properly adjusted}) / P(H=4)$

But here I run into a few problems:

1) How do I find the overall probability that $H$ = $4$? I'm confused about how to weight it.

2) Is this even a correct application of Bayes' rule? I've never heard of using it except in simple conditional probabilities and it was entirely unintuitive to me - I only thought of this combination of approaches because my professor told us that the assignment would focus on both Binomial RVs and Bayes'. Is there a better way to approach the problem from the get go?

• This looks good. You know $P[\mbox{properly}]=.9$. Also, by the law of total probability: $$P[H=4]=P[H=4|\mbox{Properly}]P[\mbox{Properly}] + P[H=4|\mbox{Not}]P[\mbox{Not}]$$ Oct 7, 2016 at 6:07
• And you are correctly using Baye's in that: $$P[\mbox{Properly}|H=4] = \frac{P[H=4|\mbox{Properly}]P[\mbox{Properly}]}{P[H=4]}$$ Oct 7, 2016 at 6:12

Let the number of high-quality items found when inspecting $n$ randomly sampled items from the machine be a binomial random variable $X$ with parameters $n$ and $\Theta$, where $\Theta$ is the probability that any given item is of high quality. That is to say, $$X \mid \Theta \sim \operatorname{Binomial}(n, \Theta), \quad \Pr[X = x \mid \Theta] = \binom{n}{x} \Theta^x (1-\Theta)^{n-x}, \quad x = 0, 1, \ldots, n.$$ Note that I have taken care to write $X \mid \Theta$, because in this Bayesian framework, $\Theta$ itself is a random variable: we are told that $$\Pr[\Theta = 0.5] = 0.9, \quad \Pr[\Theta = 0.25] = 0.1.$$ This represents the prior probability distribution of $\theta$, in which, before any items are sampled, the chance that the machine is properly adjusted is $90\%$ and when properly adjusted, the probability of a randomly selected item being high quality is $50\%$.

Now, we apply Bayes' theorem: $$\Pr[\Theta = \theta \mid X = x] = \frac{\Pr[X = x \mid \Theta = \theta]\Pr[\Theta = \theta]}{\Pr[X = x]}, \quad \theta \in \{0.25, 0.5\}.$$ The LHS is the posterior probability distribution of $\Theta = \theta$ given an observed sample $X = x$, and if we select $\theta = 0.5$, the above formula gives us the posterior probability that the machine was properly adjusted given that the number of high quality items observed is $x$. So the desired probability is $$\Pr[\Theta = 0.5 \mid X = 4] = \frac{\Pr[X = 4 \mid \Theta = 0.5] \Pr[\Theta = 0.5]}{\Pr[X = 4]} = \frac{\binom{5}{4} (0.5)^4 (1 - 0.5)^{5-4} (0.9)}{\Pr[X = 4]},$$ and this is roughly where you got stuck. The missing element is the denominator, which is the unconditional (or marginal) distribution of the probability of seeing $4$ high quality items. This is found by conditioning on $\Theta$ and using the law of total probability: $$\Pr[X = x] = \Pr[X = x \mid \Theta = 0.25]\Pr[\Theta = 0.25] + \Pr[X = x \mid \Theta = 0.5]\Pr[\Theta = 0.5].$$ This is because there are only two possible outcomes of $\Theta$, corresponding to whether the machine is properly or improperly adjusted, and only exactly one of these outcomes can occur at any given time. Therefore, $$\Pr[X = 4] = \binom{5}{4}(0.5)^4 (1 - 0.5)^{5-4} (0.9) + \binom{5}{4}(0.25)^4 (1 - 0.25)^{5-4} (0.1).$$ You will notice that the first term of this expression is precisely the numerator of the previous calculation; this is not a coincidence. I leave it to the reader to investigate and try to explain why this happens (hint: think in terms of events).

From here, the rest is just computation and I trust that you will be able to finish the exercise.