I enjoyed how the 3.16 section of the Stanford Artificial Intelligence class presented the Bayes theorem. Instead of giving a formula and expecting the alumni to apply it, they gave us a problem that the Bayes theorem would solve and expected, I believe, that we figured it out ourselves.

Being as I am counting-challenged, it took me a while to figure out a way of solving it that was simple enough that I could be reasonably sure of my results. It turned out to be a very interesting detour.

The problem was like this: the probability of having cancer is \(P(C)=0.01\); the probability of giving positive in a cancer test when you have cancer is \(P(+ \mid C)=0.9\); and the probability of giving positive when you don't have cancer is \(P(+ \mid

eg C)=0.2\). What is the probability of having cancer if you give positive in the test?

It's interesting because it is sort of how it works. A test for cancer is not tried on all the population. You find some people that have cancer, give them the test, and see what proportion comes positive; you find other people that don't have cancer, give them the test, and see how many come positive as well. But that doesn't directly tell you what proportion of the people who give positive in the test will actually have cancer.

Let's assume a population of 1000:

The bottom line represents the full population. The red at the left is the \(0.01\) who have cancer, and the green the \(0.99\) who don't. The top line is the people who give positive in the test. The orange spec at the left are those who have cancer and give positive, and the blue are those who don't have cancer but also give positive.

Zooming in:

In red on the left we have the \(0.01 \cdot 1000 = 10\) persons who have cancer, and on top in orange those among them who give positive in the test. We know that \(P(+\mid C)=0.9\) —90% of people who have cancer give positive— so \(0.9\cdot 10=9\) persons have cancer and give positive.

In blue we have the people who don't have cancer but give positive. Given that \(P(+\mid

eg C)=0.2\) —20% of people who don't have cancer give positive— there will be \(0.2\cdot 990=198\) healthy persons who give positive.

Now the answer to the problem should be obvious. We know that the test is positive, so that puts us in the top line. Out of the \(9+198=207\) persons who give positive, only \(9\) actually have cancer. So the chances of having cancer given that the test is positive are \(9/207=0.043\), only around 4.3%.

An interesting follow-up question would be to figure out how accurate the test would have to be for a positive to have a 50% chance of having cancer. One way would be to reduce the percentage of false positives from \(0.2\) to \(9/990=0.009\) (check it out, this is not obvious from the above), almost dividing it by 20.