# Set up

Consider a collection of random events $$A_1, \dots, A_n$$ and $$B_1, \dots, B_n$$. It is clear from Bayes rule that $$P(A_i \mid B_i) = \frac{P(B_i \mid A_i) P(A_i)}{P(B_i)},$$ for each $$i=1,\dots,n$$. Therefore by summing we get $$\sum_{i=1}^n P(A_i \mid B_i) = \sum_{i=1}^n \frac{P(B_i \mid A_i) P(A_i)}{P(B_i)}. \tag{1}$$

Now, we establish another fact. Define $$I \sim \mathrm{unif}\{1, \dots, n\}$$ independent of all events. Then by Bayes rule $$P(A_I \mid B_I) = \frac{P(B_I \mid A_I) P(A_I)}{P(B_I)}.$$ Expanding each of these terms using the law of total probability, we see e.g. that $$P(B_I) = \frac{1}{n} \sum_{i=1}^n P(B_i)$$ and $$P(A_I \mid B_I) = \sum_{i=1}^n P(A_i \mid B_i, I=i) P(I=i) = \frac{1}{n} \sum_{i=1}^n P(A_i \mid B_i) \tag{?}$$ and likewise for $$P(B_I \mid A_I)$$ and $$P(A_I)$$. Plugging this into the previous display, we get $$\sum_{i=1}^n P(A_i \mid B_i) = \frac{\sum_{i=1}^n P(B_i \mid A_i) \sum_{i=1}^n P(A_i)}{\sum_{i=1}^n P(B_i)}. \tag{2}$$

# Consequence and confusion

By equating the RHS terms in eqs. (1) and (2), we get $$\frac{\sum_{i=1}^n P(B_i \mid A_i) \sum_{i=1}^n P(A_i)}{\sum_{i=1}^n P(B_i)} = \sum_{i=1}^n \frac{P(B_i \mid A_i) P(A_i)}{P(B_i)}.$$ These two expressions in eq. (3) are clearly not always equal, indicating an error in the previous development. I can't find it, however I am suspicious of eq. (?). Would someone please point out the error? Thanks.

New contributor
james hoffman is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
• Such a well elaborated question for a new member. Congratulations! Commented Jul 10 at 9:37

## 1 Answer

The problem is indeed in (?). Here you are applying the law of total probability to a conditional probability space, but not quite correctly. It should be $$P(A_I\mid B_I)=\sum_{i=1}^nP(A_I\mid B_I,I=i)P(I=i\mid B_I).$$

• Earlier, I made an answer claiming that this was a common mistake made in probability. Seems like I wasn't wrong! Commented Jul 10 at 17:45