I’ve finished a script that helps understand Bayes’ Theorem.

If we have a set of mutually exclusive (aka non-overlapping) sets B_{i} for i {0, 1, 2, …, n} for some integer n, then the union of these sets forms a sample space. Lets call the sample space S. Suppose that we also have some set (also known as an event) A which is also a subset of S. Bayes’ Theorem considers the probability that one of these mutually exclusive events (one of the B_{i}‘s) caused the observed event (A).

This probability can be calculated by the formula

Pr(B_{j} | A) = | _{j}) Pr(A | B_{j}) |

_{i}) Pr(A | B_{i}) |

The theorem helps us determine the the probability of the event B_{j} given A, or in more plain English, the probability that the event B_{j} is the cause that gives rise to the observed event A. The numerator is given by the product of of the probability of the causal event (Pr(B_{j}) times the conditional probability of the observed event given the causal event (Pr(A | B_{j})). This numerator could be replaced by its equivalent statement of the set A B_{j}. Likewise, the denominator the sum (over all the causal events) of the probaility of each causal event times the conditional probability of the observed event given that particular causal event. Each term in this denominator could be replaced b its equivalent staetment A B_{i}, which when summed give the total probability of A because each pair of the B_{j}‘s is mutually exclusive. So we are able to replace the probability of A with Pr(B_{i}) Pr(A | B_{i}) because of the fundamental law of probability.

An example that would use Bayes’ Theorem is analyzing the results of an election. The set of mutually exclusive events could be membership in a political party (Democrat, Republican, or Independent). The observed event could be the election of an individual. And the conditional distributions could be the percentage of each party that voted for this individual. If we want to calculate how significant each party was to the individual’s election, we’d use Bayes’ Theorem.

The script I’ve written to help understand Bayes’ Theorem works as follows:

– A set of mutually exclusive sets is randomly generated (the number of sets also varies). These sets are called B_{i} for i (0, …, n}.

– A set A is randomly generated from the union of the B_{i}‘s.

– A table is displayed showing:

Pr(B_{i}) for each i on line 1.

Pr(A | B_{i}) for each i on line 2.

– The user is given the option to select which of the mutually exclusive sets they would like to use to calculate the probability that this set caused the event A.

– Once a set is chosen, the user clicks the “Calculate Conditional” button and Bayes’ Theorem gives the result.

– If the “show work” checkbox was checked, then the steps used in this calculation are also shown.

– All work is done using fractions to give an idea of where the numbers come from.

Other Blogs that have covered this topic:

Better Explained

Bayes’ Theorem-qed