# Bayes' Rule with combinations

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?

Let $A_1$ denote the event that the machine is adjusted properly, let $A_2$ denote the event that it is adjusted improperly, and let $B$ be the event that four of the five inspected items are of high quality. Then $Pr(A_1|B) = \frac{Pr(A_1) Pr(B | A_1)} {Pr(A_1) Pr(B | A_1) + Pr(A_2) Pr(B | A_2)} = \frac{(0.9) \binom{5}{4} (0.5^5)}{(0.9) \binom{5}{4} (0.5^5) + (0.1) \binom{5}{4} (0.25^4) (0.75)} = \frac{96}{97}$

Suppose that one additional item, which was produced by the machine at the same time as the other five items, is selected and found to be of medium quality. What is the new posterior probability that the machine was adjusted properly?

The prior probabilities before this additional item is observed are the values found in part (a): $Pr(A_1) = \frac{96}{97}$ and $Pr(A_2) = \frac{1}{97}$. Let $C$ denote the event that the additional item is of medium quality. Then $Pr(A_1|C)= \frac{\frac{96}{97} * \frac{1}{2}}{\frac{96}{97} * \frac{1}{2} + \frac{1}{97} * \frac{3}{4}} = \frac{64}{65}$

My solution: Then $Pr(A_1|B) = \frac{(0.9) \binom{6}{4} (0.5^5)}{(0.9) \binom{6}{4} (0.5^5) + (0.1) \binom{6}{4} (0.25^4) (0.75^2)} = \frac{64}{65}$

I receive the same answer as the solution, but I'm confused on how in the solution the second question can take the answer to the first question and use that result. Since we need to account for combinations, the answer to the first question needed $\binom{5}{4}$, so wouldn't an additional item need to account for $\binom{6}{4}$, which would require recalculation of the first answer?

It is because the event of $B$ and $C$ are conditionally independent for a given event of $A_1$ (or $A_2$)

Also you are actually looking for $\mathsf P(A_1\mid B,C)$ : the conditional probability that the machine is tuned correctly given both the initial result ($B$) and the extra result ($C$).   You are updating the posterior probability on acquiring new data.

\begin{align}\mathsf P(A_1\mid B,C)~&=\dfrac{\mathsf P(A_1,C\mid B)}{\mathsf P(A_1,C\mid B)+\mathsf P(A_2,C\mid B)} \\[1ex]&= \dfrac{\mathsf P(A_1\mid B)\,\mathsf P(C\mid A_1,B)}{\mathsf P(A_1\mid B)\,\mathsf P(C\mid A_1,B)+\mathsf P(A_2\mid B)\,\mathsf P(C\mid A_2,B)}\\[1ex]&= \dfrac{\mathsf P(A_1\mid B)\,\mathsf P(C\mid A_1)}{\mathsf P(A_1\mid B)\,\mathsf P(C\mid A_1)+\mathsf P(A_2\mid B)\,\mathsf P(C\mid A_2)} &&B\perp C\mid A_n \\[1ex] &= \dfrac{\tfrac{96}{97} \cdot \tfrac{1}{2}}{\tfrac{96}{97} \cdot \tfrac{1}{2} + \tfrac{1}{97} \cdot \tfrac{3}{4}}\\[1ex] &= \dfrac{64}{65}\end{align}

Which of course should equal $\dfrac{\mathsf P(A_1)\,\mathsf P(B,C\mid A_1)}{\mathsf P(A_1)\,\mathsf P(B,C\mid A_1)+\mathsf P(A_2)\,\mathsf P(B,C\mid A_2)}\\ =\dfrac{0.9\binom 54\binom 10 0.5^6}{0.9\binom 54\binom10 0.5^6+0.1\binom 54\binom 10 0.25^40.75^2}\\ = \dfrac{\tfrac{0.9\binom 54 0.5^5}{0.9\binom 54\binom10 0.5^5+0.1\binom 54 0.25^40.75}0.5}{\tfrac{0.9\binom 54 0.5^5}{0.9\binom 54\binom10 0.5^5+0.1\binom 54 0.25^40.75}0.5+\tfrac{0.1\binom 54 0.25^40.75}{0.9\binom 54\binom10 0.5^5+0.1\binom 54 0.25^40.75}0.75}$

Since we need to account for combinations, the answer to the first question needed $\binom 54$, so wouldn't an additional item need to account for $\binom 64$, which would require recalculation of the first answer?

Well, actually the event of one sample of $4$ high quality and $1$ medium, plus another sample of $1$ medium, would be counted by $\binom 54\binom 10$, not $\binom 65$.   Fortuitously the binomial coefficients in the numerator and denominator of the probability cancel so you obtained the right answer anyway.