Bayes
Bayes
Source: https://www.statisticshowto.com/probability-and-statistics/probability-main-
index/bayes-theorem-problems/
Bayes’ theorem is a way to figure out conditional probability. Conditional probability is the
probability of an event happening, given that it has some relationship to one or more other
events. For example, your probability of getting a parking space is connected to the time of day
you park, where you park, and what conventions are going on at any time. Bayes’ theorem is
more nuanced: it gives you the actual probability of an event given information about tests.
• “Events” Are different from “tests.” For example, there is a test for liver disease, but
that’s separate from the event of actually having liver disease.
• Tests are flawed: just because you have a positive test does not mean you actually have
the disease. Many tests have a high false positive rate. Rare events tend to have higher
false positive rates than more common events. We’re not just talking about medical tests
here. For example, spam filtering can have high false positive rates. Bayes’ theorem takes
the test results and calculates your real probability that the test has identified the event.
The Formula
Bayes’ Theorem (also known as Bayes’ rule) is a deceptively simple formula used to calculate
conditional probability. The Theorem was named after English mathematician Thomas Bayes
(1701-1761). The formal definition for the rule is:
In most cases, you can’t just plug numbers into an equation; You have to figure out what your
“tests” and “events” are first. For two events, A and B, Bayes’ theorem allows you to figure out
p(A|B) (the probability that event A happened, given that test B was positive) from p(B|A) (the
probability that test B happened, given that event A happened). It can be a little tricky to wrap
your head around as technically you’re working backwards; you may have to switch your tests
and events around, which can get confusing. An example should clarify what I mean by “switch
the tests and events around.”
Bayes’ Theorem Example #1
You might be interested in finding out a patient’s probability of having liver disease if they are
an alcoholic. “Being an alcoholic” is the test (kind of like a litmus test) for liver disease.
• could mean the event “Patient has liver disease.” Past data tells you that 10% of patients
entering your clinic have liver disease. P(A) = 0.10.
• B could mean the litmus test that “Patient is an alcoholic.” Five percent of the clinic’s
patients are alcoholics. P(B) = 0.05.
• You might also know that among those patients diagnosed with liver disease, 7% are
alcoholics. This is your B|A: the probability that a patient is alcoholic, given that they
have liver disease, is 7%.
In a particular pain clinic, 10% of patients are prescribed narcotic pain killers. Overall, five
percent of the clinic’s patients are addicted to narcotics (including pain killers and illegal
substances). Out of all the people prescribed pain pills, 8% are addicts.
Question you are asking: If a patient is an addict, what is the probability that they will be
prescribed pain pills?
(Obviously, there are other questions you could ask, then the analysis would be different.)
Step 1: Figure out what your event “A” is from the question. That information is in the
italicized part of this particular question. The event that happens first (A) is being prescribed pain
pills. That’s given as 10%.
Step 2: Figure out what your event “B” is from the question. That information is also in the
italicized part of this particular question. Event B is being an addict. That’s given as 5%.
Step 3: Figure out what the probability of event B (Step 2) given event A (Step 1). In other
words, find what (B|A) is. We want to know “Given that people are prescribed pain pills, what’s
the probability they are an addict?” That is given in the question as 8%, or .8.
Step 4: Insert your answers from Steps 1, 2 and 3 into the formula and solve.
P(A|B) = P(B|A) * P(A) / P(B) = (0.08 * 0.1)/0.05 = 0.16
There are several forms of Bayes’ Theorem out there, and they are all equivalent (they are just
written in slightly different ways). In this next equation, “X” is used in place of “B.” In addition,
you’ll see some changes in the denominator. The proof of why we can rearrange the equation
like this is beyond the scope of this . However, if you come across a question involving medical
tests, you’ll likely be using this alternative formula to find the answer:
The first step into solving Bayes’ theorem problems is to assign letters to events:
• A = chance of having the faulty gene. That was given in the question as 1%. That also
means the probability of not having the gene (~A) is 99%.
• X = A positive test result.
So:
Now we have all of the information we need to put into the equation:
P(A|X) = (.9 * .01) / (.9 * .01 + .096 * .99) = 0.0865 (8.65%)
The probability that a person actually has the gene, given the test result, is lowered considerably
by the large number of false positives ! The person could be one of those!
Like this:
The probability of getting a positive result on the test. That equals the chance of a true positive
(Step 1) plus a false positive (Step 2) = .009 + .09504 = 0.10404. It’s “simple” if you ask the
right question first (What is the probability that I get a positive test?). Then assess my
probability of getting a false positive (it is remarkably high!).
References
Dodge, Y. (2008). The Concise Encyclopedia of Statistics. Springer.
Everitt, B. S.; Skrondal, A. (2010), The Cambridge Dictionary of Statistics, Cambridge
University Press.
Gonick, L. (1993). The Cartoon Guide to Statistics. HarperPerennial.