A Bayes theorem calculator updates a probability when you learn something new. It answers questions like: if a test is 99 percent accurate and a person tests positive, what is the chance that they really have the condition? Enter how common it is, and the sensitivity and specificity of the test, and you get the chance, the share of positives that are false, and the numbers in a group of 100,000 people. It also handles any event, and several possible causes. It runs in your browser.
How to use the Bayes theorem calculator
- Choose medical test, event or several causes.
- Enter the percentages, or the list of causes.
- Press Calculate.
The theorem
The Wikipedia article on Bayes' theorem states that P(A | B) = P(B | A) × P(A) ÷ P(B), as long as P(B) is not zero. The chance of B itself comes from the law of total probability: for the two cases A and not A, P(B) = P(B | A) × P(A) + P(B | not A) × P(not A).[1] So the chance of A given B is P(B | A) × P(A) divided by that sum. The calculator uses this form. You supply the prior chance of A, the chance of B if A is true, and the chance of B if A is false, and it gives the updated chance.
The drug-test example
The article works through a drug test. The test has a sensitivity of 99 percent, which is the true positive rate, and a specificity of 99 percent, which is the true negative rate, so it gives a false positive for 1 percent of people who do not use the drug. Only 0.3 percent of people use the drug. The chance that a person with a positive result is really a user is (0.99 × 0.003) ÷ (0.99 × 0.003 + 0.01 × 0.997), which is about 23 percent, so most positive results are false.[1] Enter 0.3, 99 and 99 into the test mode to see the same result: 22.95 percent. This is called the positive predictive value, a name that the page does not use.
Counting people
The calculator also shows the numbers in a group of 100,000 people, which makes the result easier to understand. With the figures above, 300 people use the drug and 99,700 do not. The test finds 297 of the 300 users, and wrongly flags 997 of the others, so there are 1,294 positive results and only 297 of them are true. That is 297 ÷ 1,294 = 23 percent. The same group has 98,703 true negatives and 3 false negatives, so a negative result is correct 99.997 percent of the time. This counting is our own way of showing the calculation.
A very rare condition
Another example on the page is about a rare cancer. The chance of the cancer is 1 in 100,000, and 10 in 99,999 healthy people have the same symptoms. A person with the symptoms then has a chance of about 9.1 percent of having the cancer.[1] Enter it into the event mode with a prior of 0.001 percent, a chance of the symptoms of 100 percent if the cancer is present, and 0.01 percent if it is not, and the calculator gives 9.09 percent. The lesson is the same: when a condition is rare, even a good test gives many false alarms.
Several possible causes
When there are more than two causes, the extended form divides by the sum over all of them. The page's example is a set of bent coins in an urn: two coins of type A that land heads half of the time, two of type B that land heads 60 percent of the time, and one of type C with 90 percent. The chances of picking each are 2/5, 2/5 and 1/5, and the chance of heads is 0.62. Given heads, the chance of type A is 0.2 ÷ 0.62, about 32 percent.[1] In the several causes mode, enter 0.4, 0.5 on the first line, 2/5, 0.6 on the second, and 20%, 0.9 on the third, and you get 32.3, 38.7 and 29.0 percent.
Sensitivity and specificity
The page names sensitivity as the true positive rate and specificity as the true negative rate, and the false positive rate is 1 minus the specificity.[1] A test can have high values of both and still give mostly false positives if the condition is rare. This is why the prevalence matters so much. When you read about a test, ask how common the condition is in the people who are tested. For people with symptoms or risk factors, the prevalence is higher, and a positive result means more.
Using the odds form
Bayes' theorem can also be used by thinking in terms of how many people in a group have the result. List a group of people, split it by who has the condition, apply the test rates, and compare the true positives with all the positives. This is the same arithmetic in a form that is easier to check, and the calculator's group counts follow it. Use it when you need to explain the result to someone who is not at ease with probabilities.
Common mistakes
- Ignoring how common it is. The prior chance changes the answer a great deal.
- Mixing up P(A | B) and P(B | A). A test's accuracy is not the chance of the condition.
- Using percentages and decimals together. Choose one form.
- Forgetting the false positives. They come from the many people who do not have the condition.
What next
Use this often? Add Bayes Theore to your Home screen.
Frequently asked questions
What is a Bayes theorem calculator?
A tool that updates a probability using Bayes' theorem, for example the chance of a condition after a positive test.
What is Bayes' theorem?
P(A | B) = P(B | A) × P(A) ÷ P(B), where P(B) = P(B | A) × P(A) + P(B | not A) × P(not A).
Why are most positive results false in the drug test example?
The condition is rare, 0.3 percent, so the 1 percent of false positives among the many non-users outnumber the true positives. The chance of a real user is about 23 percent.
What are sensitivity and specificity?
Sensitivity is the true positive rate and specificity is the true negative rate. The false positive rate is 1 minus the specificity.
Can I use it for more than two causes?
Yes. The several causes mode takes a prior chance and a chance of the result for each cause.
Sources
Was this tool helpful?
What went wrong?
We only receive the reason you pick, never what you typed into the tool.
Thanks for your feedback.