Visualizing Bayes’ theorem
I recently came up with what I think is an intuitive way to explain Bayes' Theorem. I searched in google for a while and could not find any article that explains it in this particular way.
Of course there's the wikipedia page, that long article by Yudkowsky, and a bunch of other explanations and tutorials. But none of them have any pictures. So without further ado, and with all the chutzpah I can gather, here goes my explanation.
Probabilities
One of the easiest ways to understand probabilities is to think of them in terms of Venn Diagrams. You basically have a Universe with all the possible outcomes (of an experiment for instance), and you are interested in some subset of them, namely some event. Say we are studying cancer, so we observe people and see whether they have cancer or not. If we take as our Universe all people participating in our study, then there are two possible outcomes for any particular individual, either he has cancer or not. We can then split our universe in two events: the event "people with cancer" (designated as A), and "people with no cancer" (or ~A). We could build a diagram like this:
So what is the probability that a randomly chosen person has cancer? It is just the number of elements in A divided by the number of elements of U (the Universe). We denote the number of elements of A as |A|, and read it the cardinality of A. And define the probability of A, P(A), as

Since A can have at most the same number of elements as U, the probability P(A) can be at most one.
Good so far? Okay, let's add another event. Let's say there is a new screening test that is supposed to measure something. That test will be "positive" for some people, and "negative" for some other people. If we take the event B to mean "people for which the test is positive". We can create another diagram:
So what is the probability that the test will be "positive" for a randomly selected person? It would be the number of elements of B (cardinality of B, or |B|) divided by the number of elements of U, we call this P(B), the probability of event B occurring.

Note that so far, we have treated the two events in isolation. What happens if we put them together?
We can compute the probability of both events occurring (AB is a shorthand for A∩B) in the same way.

But this is where it starts to get interesting. What can we read from the diagram above?
We are dealing with an entire Universe (all people), the event A (people with cancer), and the event B (people for whom the test is positive). There is also an overlap now, namely the event AB which we can read as "people with cancer and with a positive test result". There is also the event B - AB or "people without cancer and with a positive test result", and the event A - AB or "people with cancer and with a negative test result".
Now, the question we'd like answered is "given that the test is positive for a randomly selected individual, what is the probability that said individual has cancer?". In terms of our Venn diagram, that translates to "given that we are in region B, what is the probability that we are in region AB?" or stated another way "if we make region B our new Universe, what is the probability of A?". The notation for this is P(A|B) and it is read "the probability of A given B".
So what is it? Well, it should be
And if we divide both the numerator and the denominator by |U|
we can rewrite it using the previously derived equations as
What we've effectively done is change the Universe from U (all people), to B (people for whom the test is positive), but we are still dealing with probabilities defined in U.

Now let's ask the converse question "given that a randomly selected individual has cancer (event A), what is the probability that the test is positive for that individual (event AB)?". It's easy to see that it is
Now we have everything we need to derive Bayes' theorem, putting those two equations together we get
which is to say P(AB) is the same whether you're looking at it from the point of view of A or B, and finally

Which is Bayes' theorem. I have found that this Venn diagram method lets me re-derive Bayes' theorem at any time without needing to memorize it. It also makes it easier to apply it.
Example
Take the following example from Yudowsky:
1% of women at age forty who participate in routine screening have breast cancer. 80% of women with breast cancer will get positive mammograms. 9.6% of women without breast cancer will also get positive mammograms. A woman in this age group had a positive mammography in a routine screening. What is the probability that she actually has breast cancer?
First of all, let's consider the women with cancer
Now add the women with positive mammograms, note that we need to cover 80% of the area of event A and 9.6% of the area outside of event A.
It is clear from the diagram that if we restrict our universe to B (women with positive mammograms), only a small percentage actually have cancer. According to the article, most doctors guessed that the answer to the question was around 80%, which is clearly impossible looking at the diagram!
Note that the efficacy of the test is given from the context of A, "80% of women with breast cancer will get positive mamograms". This can be interpreted as "restricting the universe to just A, what is the probability of B?" or in other words P(B|A).
Even without an exact Venn diagram, visualizing the diagram can help us apply Bayes' theorem:
- 1% of women in the group have breast cancer → P(A) = 0.01
- 80% of those women get a positive mammogram, and 9.6% of the women without breast cancer get a positive mammogram too → P(B) = 0.8 P(A) + 0.096 (1 - P(A)) = 0.008 + 0.09504 = 0.10304
- we can get P(B|A) straight from the problem statement, remember 80% of women with breast cancer get a positive mammogram → P(B|A) = 0.8
Now let's plug those values into Bayes' theorem
which is 0.0776 or about a 7.8% chance of actually having breast cancer given a positive mammogram.

May 1st, 2009 - 13:37
Very well explained! I’ve been reviewing the fundamentals of Bayes theory recently to try to get my head around Bayesian networks from a non stats background. Don’t suppose you could point me in the direction of a similarly visual explanation for that, or maybe consider it in a future post?
May 2nd, 2009 - 10:19
Hm. Bayesian networks… I don’t know of any “visual explanation” of those. I’ll take a look and see if I can come up with something. Thanks for the comment.
July 19th, 2011 - 15:30
How about a water/hydraulics method? People sometimes speak of ‘probability-mass’ or ‘probability-fluid’, so you could depict the network as a series of tubes changing in size and then the volume of output is the answer.
May 1st, 2009 - 13:59
Bravo! I actually did the same thing with Venn diagrams to explain it to myself awhile back – I’m glad you took the time to make it clear to others.
May 1st, 2009 - 14:06
How can it be hard to derive Bayes formula if left and right part is essentially the same (A becomes B, B becomes A).
May 2nd, 2009 - 10:21
If I understand your question correctly, you’re saying “what happens when A and B are the same?”. In that case, P(AB) = P(A) = P(B), and P(A|B) = 1. Which is saying “given that event A occurred, what is the probability of event A occurring?”. It should be pretty obvious that it is 1.
May 1st, 2009 - 14:11
http://yudkowsky.net/rational/bayes
May 1st, 2009 - 14:37
This was fantastic. Thank you.
May 1st, 2009 - 15:01
Best explanation of Bayesian, ever, period!!
May 1st, 2009 - 15:14
Great job man! Visualizing this fascinating theorem was a great idea. I dunno though, I always found the actual examples for Bayes’s Theorem to be misleading… I guess that’s just the nature of statistics in odd contexts though!
May 1st, 2009 - 18:31
Dmitriy: Linked in the intro.
Oscar: “Of course there’s the wikipedia page, that long article by Yudkowsky, and a bunch of other explanations and tutorials. But none of them have any pictures.” <– the Java applets/visualizations don’t count as pictures?
May 2nd, 2009 - 10:24
True, the Yudkowsky article has some pictures, and if you keep Java off like I do, all you see are the pictures. My main problem with Yudkowsky’s article is that it’s really, really, really, long! If you are looking to just get the gist of what Bayes’ theorem is saying you are not going to read that much.
May 1st, 2009 - 21:40
Most beautiful and simple explanation. Thanks a lot
May 1st, 2009 - 21:47
Thanks a lot! This was the first time that Bayes actually made sense to me. It’s much easier to understand when visualized.
May 1st, 2009 - 23:41
You are right, memorizing this method gives a hard-to-forget method for rederiving and re-learning Bayes’ rule.
May 2nd, 2009 - 02:33
Thank you for this article!
I really liked the last bit, where you showed the cancer example. That was a good example of “applying the theory shows why you should learn the theory”.
Jens
May 2nd, 2009 - 03:38
Nice. I created something similar a while back due to constantly having to explain this in #math on IRC:
http://imagebin.org/47539
The application to mammograms is a nice one though. Bookmarked!
May 2nd, 2009 - 05:17
This is the absolute best derivation of Bayes theorem I have ever seen, including a course in statistics I did last year. Your post definitely needs to go up on the wikipedia page, under the intuitive reasoning part.
May 2nd, 2009 - 10:58
This is great. Very useful.
I don’t want to be a pedant, and I may be wrong, but aren’t these technically Euler diagrams and not Venn diagrams?
May 2nd, 2009 - 18:05
Well, if you consider the fact that the sets are only defined within the Universe, then they are indeed showing all the possible intersections. Thus they are Venn diagrams.
May 4th, 2009 - 02:59
Wow.
I’ve read quite a few explanations of Bayes’ theorem and this is the first which (in the space of really a few minutes!) has got the point across so succinctly and clearly I now actually understand it.
My thanks.
May 4th, 2009 - 04:44
Brilliant! Thank you!
May 4th, 2009 - 06:58
Thanks a lot!!!
May 4th, 2009 - 10:52
Thank you for re-sparking my love for Discreet Mathematics.
I fondly remember studying this, years ago, but had forgotten the enjoyment of it.
I eagerly await any further of your works.
Perhaps animated…?, perhaps interactive…?
Again Thanks.
May 5th, 2009 - 12:27
This should be made into a visualization app for Google’s new public data search and frankly any data set. Anyone want to work on it with me?
May 5th, 2009 - 14:24
Great job, short, clear and effective – thanks for taking the time to create it!
May 5th, 2009 - 15:34
The exact problem at the end is a good example of how stats can confuse the lay man. Test accuracy should be reported in the rate of false negatives, rather than true positives. The cost of a large number of false negatives can be great relative to a large number of false positives. However, depending on your situation, you could have a lot of false negatives AND false positives, indicating that your test is not well-correlated for the condition being tested for. In fact, just calculating the correlation coefficient is an important step.
May 7th, 2009 - 19:24
Great Job, and excellent example :P | Muy Buen trabajo y excelentes ejemplos!
May 10th, 2009 - 14:18
Great explanation! I teach high school mathematics and am stealing your visualization, example and all, to use in one of my next lessons! :-)
May 28th, 2009 - 15:10
hmm… i think the easiest way to understand bayes theorem is to multiply both sides to get..
P(B) P(A|B) = P(A) P(B|A)
both of these are just P(A intersect B) – probability of A and B is the same as the probability of A times the probability of B given A, or the probability of B times the probability of A given B
May 30th, 2009 - 18:51
David Newman’s book, Hippocrates’ Shadow, Simon&Schuster 2008 has an good treatment of of this in relation to medical interventions and clinical trials. He uses a bar graph variant to demonstrate things Baysean. Good, but not as good as your demonstration! His discussion of this topic sent me to the web where I finally and gratefully got to your visualization! Thanks.
June 5th, 2009 - 00:26
i n really convay to this method of learning of process
June 8th, 2009 - 18:45
this is freagin awesome explanation. thank u :)
June 10th, 2009 - 07:09
I too teach mathematics and am impressed with your clear explaination.
Well done, and thanks for taking the time to lay it out.
June 11th, 2009 - 04:24
An addendum that “completes” the Bayes theorem so that the denominator is the same as in the Yudkowsky article would be nice. Graphically, that would be saying that the area of B is the “union” of two sections: 1. the non-overlap, which is areas in B “starting with” the areas that are NOT in A (the ~A part of the universe) i.e. P(B|~A) * P(~A), 2. the overlap, which is areas in B “starting with” the areas that ARE in A i.e. P(B|A) * P(A). It’s more helpful for applications in which the data makes it easier to figure out probabilities of A and relate those to B, than to figure out probabilities of B.
July 16th, 2009 - 18:48
Professor Oscar,
You are a great prof! You set a benchmark for us trying-to-be’s.
A question. When can I write
P(AB/R) = P(A/R) + P(B/R) ?
What conditions need to be imposed on A, B and R?
Thanks Professor!
Tapan Bagchi at the Indian Institute of Technology Kharagpur
July 19th, 2009 - 03:46
thank you very much…very nice article…
desiNerd,
IITKGP
August 14th, 2009 - 02:23
that’s a really appealing way of expressing Bayes’ theorem
how would the venn-diagram be if the conditional probability of A
didn’t depend on B i.e P(A/B)=P(A) ?
August 14th, 2009 - 12:31
Very nice artice article in every meaning of the word. Have you publised elsewhere?
August 22nd, 2009 - 03:19
Great work dude….I was banging my head to develop intuition on Bayes theorem. Now I got the idea clearly…
Thank u very much..
August 23rd, 2009 - 15:57
May want to check the book by Wonnocott and Wonnocott. They have a visual way of explaining Bayes Theorem
September 16th, 2009 - 10:35
Beautiful explanation. I was searching for something that would help me explain it to undergrads…thanks a bunch.
October 2nd, 2009 - 10:47
This is one of the best explanations I’ve found. Perhaps we can see if I really understand it by trying a real world problem I’m wrestling with.
Here’s the data:
– The odds of a chest pain (CP) being caused by a heart attack is 40%.
– The odds of a CP being caused by other factors (anxiety, depression, etc.) is 60%.
– The odds of a heart attack occurring to a female above age 50 is 80%.
– The odds of a heart attack occurring to a female under age 50 is 20%.
I am presented with a 24 year old female who says she is having chest pain. What is the probability that her chest pain is caused by a heart attack? Is it 0.4 x 0.2 = 0.08?
Also, 78% of patients having heart attacks present with diaphoresis (sweating), so 22% of patients having heart attacks don’t sweat. This female is not sweating, so are the odds of her having a heart attack 0.22 x 0.08 = 0.0176?
Thank you!
October 11th, 2009 - 04:26
You beat me to it! I got the idea of thinking about Bayes’ theorem by Venn diagrams by reading Reza’s An Introduction to Information Theory.
November 26th, 2009 - 15:09
Can someone help me with this question?
One fifth of customers entering a certain Future
Shop store are under 20 years old. 5% of these under 20 year olds make a purchase over $500,
and 10% of the customers 20 years or older make a purchase over $500. What is the probability
that is a major purchase is made, it was by a person 20 years or older?
December 8th, 2009 - 18:58
Just wanted to convey my thanks.
I am teaching this subject to undergrads at a Chinese university and found your explanations and visuals a huge help.
December 13th, 2009 - 18:02
Good visual explanation. I used it to work out a probability but don’t know if the professor is going to reject it.
Thanks.
February 9th, 2010 - 22:57
this proof was awesome.
June 15th, 2010 - 06:01
Really “Great” Job. Keep doing such good job, humanity will be enriched by people like you. Hats off to You!!
August 24th, 2010 - 00:28
Great! It’s subtle and effective. Thanks a lot.
July 22nd, 2011 - 14:50
Great common sense here. Wish I’d thought of that.
November 2nd, 2010 - 08:40
Very nice illustration of how to think of the probabilities.
Well done.
November 15th, 2010 - 08:24
i want bayes theorem application
November 22nd, 2010 - 09:12
Thanks a lot. It was useful for me as a Bioinformatics student.
Good work! Wish you inspiration for making more good stuff!
November 29th, 2010 - 09:45
great awesome .no words
December 13th, 2010 - 15:34
U = me
A = Satisfaction with the explanation
p(A) = |A|/|U| = 1
December 19th, 2010 - 19:17
Very helpful demonstration.
For a nearly identical explanation of Bayes theorem using Venn diagrams, see Bolstad’s book, Introduction to Bayesian Statistics.
January 20th, 2011 - 19:17
Excellent explanation!
April 9th, 2011 - 21:07
Cool! I just tried to do something like this myself using a “sieve” analogy. Check it out HERE. Someone linked to your example and I agree it’s more intuitive, though I commented on one aspect of the sieve I like a little better HERE. Thanks for putting this together!
May 9th, 2011 - 17:32
very useful. Thank you
May 12th, 2011 - 20:19
A great blogpost, I just passed this onto a colleague who was doing a little analysis on this. And he in fact bought me breakfast because I found it for him. smile. So let me reword that: Thank you for the treat! But yeah Thanks for taking the time to discuss this, I feel strongly about it and enjoy learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more details? It is extremely helpful for me. Two thumb up for this blog!
May 27th, 2011 - 04:16
It is so great explanation.Now I have bookmarked your site.Now I regularly visit your site to enhance my understanding.
June 25th, 2011 - 14:52
This is the most concise and comprehensive explanation of Bayes theorem that I’ve ever read. Thanks a lot!
July 4th, 2011 - 21:49
Thank you for your post, I enjoyed reading it.
May I ask… what software did you draw your diagrams with?
July 5th, 2011 - 13:45
I drew the diagrams with OmniGraffle: http://www.omnigroup.com/products/omnigraffle/
July 6th, 2011 - 18:41
This explanation is exactly what I was looking for. Hats off to you.
August 14th, 2011 - 19:07
I’d like to use your explanation in an on-line high school class. Can I get you permission to copy it into our course material, with credit given to you as the source?
September 4th, 2011 - 07:37
I hate giving a “me too” answer, but I really must. This is the best explanation of Bayes’ theorem that I’ve ever seen. Great job!
September 4th, 2011 - 16:00
outstanding, very useful, will start using with my students
September 22nd, 2011 - 22:31
I drew up a similar explanation about a year ago to explain why, even though there are more poor whites than poor blacks in the world, the perception that most black people are poor is not incorrect. I used current census data at the time, and realized the person registering the complaint on twitter was making the very natural error of inverting probabilities. Here was my illustration: http://cl.ly/V2Y
September 22nd, 2011 - 22:38
I should have said this was the natural error of ignoring base rates, not inverting probabilities.
October 20th, 2011 - 11:43
I think your explanation is flawed. You said P(A) = | A | / |U|, but that is only true if all elements of A have the same probability. In general that is a false statement.
October 27th, 2011 - 11:46
I didn’t want to overcomplicate the example.
October 21st, 2011 - 20:46
>80% of women with breast cancer will get positive mammograms. 9.6% of women
>without breast cancer will also get positive mammograms.
80% have cancer and 9.6% don’t have cancer (when you have positive mammogram). Why doesn’t 80 + 9.6 addup to 100%? What probabilities are remaining?
Damn! I wish I had slept in my math classes
October 22nd, 2011 - 11:57
I agree, I can’t understand how to figure out Pr (B) :(
I’ve got a stats module in my masters and having come from a non mathematical background… I’m struggling a bit.
October 27th, 2011 - 11:42
P(B) is the total probability of B, it’s the chance of B happening regardless of whether A happens. Thus, P(B) = P(B|A)P(A) + P(B|¬A)P(¬A).
October 27th, 2011 - 11:46
80% of women with breast cancer will get a positive mammogram means that P(positive mammogram | woman has cancer) = 0.8.
The remaining 20% is the probability of getting a negative mammogram given that the woman has cancer.
The 9.6 comes from the other part of the population, i.e. women without cancer that also get a positive mammogram.
In general, P(B | A) + P(¬B | A) will sum to 1, but P(B|A) + P(B|¬A) will not as they are unrelated probabilities.
November 1st, 2011 - 00:24
very useful. thank you
November 14th, 2011 - 16:33
Dear Oscar,
A clear presentation – a pleasure to read…
November 25th, 2011 - 22:41
Nicely done. A similar (and equally intuitive and effective) visual explanation of conditional probability and Bayes theorem based on Venn diagrams can be found in Bolstad’s textbook on Bayesian Statistics.
December 8th, 2011 - 14:27
Very usefull article
Wiki page must have link of Such a good and easy to under stand article.
Thank you.
January 22nd, 2012 - 08:14
Outstanding! I’ve been trying to get my head around this for some time and your explanation made everything fall into place. Nicely done. Thanks for posting this.