The Canonical Bayesian cancer question answered in PYMC

That’s a nice simulation, but this one’s easy to do analytically—it’s why it’s the first example. Let z = 1 if the patient has cancer and let y = 1 if they get a positive test. Then

\begin{align} \Pr[z = 1 | y = 1] &= \dfrac{\Pr[z = 1, y = 1]}{\Pr[y = 1]} \\[8pt] &= \dfrac{\Pr[z=1, y=1]}{\Pr[z=1, y=1] + \Pr[z=0, y=1]} \\[8pt] &= \dfrac{\Pr[z=1] \cdot \Pr[y=1 | z=1]}{\Pr[z=1] \cdot \Pr[y=1 \mid z=1] + \Pr[z=0] \cdot \Pr[y=1 | z = 0]} \\[8pt] &= \frac{0.008 \cdot 0.98} {0.008 \cdot 0.98 + (1 - 0.008) \cdot (1 - 0.97)} \\[4pt] &= 0.21 \end{align}

First line is just definition of conditional probability, denominator in second from total law of probability, the third line is just the chain rule, and the rest is just plugging in numbers.

3 Likes