Bayes Theorem Calculator
Use this Bayes theorem calculator to find P(A|B) from a prior probability and new evidence. Enter probabilities as decimals and get the posterior probability with a clear, step-by-step solution.
Enter probabilities as decimals from 0 to 1. Example results are shown automatically. After changing the values, click Calculate to update the results.
How to Use the Bayes Theorem Calculator
Using this Bayes' Theorem calculator is simple. Whether you know the total probability of an event or only conditional probabilities, just follow these steps.
1. Select the Input Type
Choose the correct mode based on the information you have:
- P(B) Known: Use this if you are given the overall probability of event B.
- P(B) Unknown: Use this if you are given the probability of B occurring when A is true and when A is false.
2. Enter the Probabilities
Input the probabilities as decimals between 0 and 1.
For P(B) Known:
- Prior probability, P(A): The initial probability of event A.
- Likelihood, P(B|A): The probability of event B given that event A occurred.
- Probability of evidence, P(B): The total probability of event B.
For P(B) Unknown:
- Prior probability, P(A): The initial probability of event A.
- Likelihood, P(B|A): The probability of event B given that event A occurred.
- Probability of B given not A, P(B|not A): The probability of event B given that event A did not occur.
3. Calculate the Posterior Probability
Click "Calculate" to find the updated probability of event A given that event B occurred. The calculator will provide the answer and a detailed step-by-step solution showing how the Bayes formula was applied.
What is Bayes' Theorem?
Bayes' Theorem is a mathematical formula used for calculating conditional probability. It allows you to update your beliefs or the probability of an event based on new evidence or information.
In simpler terms, it answers the question: "If we know the probability of A, and we observe B, how does that change the probability of A?"
It is widely used in various fields, including medicine (interpreting test results), machine learning (spam filtering), and finance (risk assessment).
Bayes' Theorem Formula
The standard formula for Bayes' Theorem is:
Where:
- P(A|B) is the posterior probability (the probability of A given B).
- P(B|A) is the likelihood (the probability of B given A).
- P(A) is the prior probability (the initial probability of A).
- P(B) is the marginal probability of the evidence.
How to Calculate Bayes Theorem When P(B) is Known
If you know the overall probability of event B, calculating the posterior probability is straightforward. Let's look at an example.
Suppose 1% of a population has a rare disease (A). A test for the disease is positive (B) in 5% of the general population. If a person has the disease, the test is positive 99% of the time.
What is the probability that a person who tests positive actually has the disease?
1. Identify the given information:
- Prior probability, P(A) = 0.01
- Probability of evidence, P(B) = 0.05
- Likelihood, P(B|A) = 0.99
2. Apply Bayes' formula:
P(A|B) = [P(B|A) × P(A)] / P(B)
P(A|B) = [0.99 × 0.01] / 0.05
P(A|B) = 0.0099 / 0.05
P(A|B) = 0.198
Conclusion: Even with a positive test, there is only a 19.8% chance the person has the disease.
How to Calculate Bayes Theorem When P(B) is Unknown
Often, you don't know the overall probability of event B. Instead, you know the probability of B occurring when A is true and when A is false. In this case, you must first calculate P(B) using the Law of Total Probability.
Let's look at an example.
Suppose 20% of all emails you receive are spam (A). The word "free" (B) appears in 60% of spam emails, but only 5% of regular (not spam) emails.
If you receive an email containing the word "free", what is the probability it is spam?
1. Identify the given information:
- P(A) = 0.20
- P(not A) = 1 - 0.20 = 0.80
- P(B|A) = 0.60
- P(B|not A) = 0.05
2. Calculate P(B):
P(B) = [0.60 × 0.20] + [0.05 × 0.80]
P(B) = 0.12 + 0.04 = 0.16
3. Apply Bayes' formula:
P(A|B) = [P(B|A) × P(A)] / P(B)
P(A|B) = [0.60 × 0.20] / 0.16
P(A|B) = 0.12 / 0.16
P(A|B) = 0.75
Conclusion: There is a 75% chance the email is spam.
Bayes Theorem vs Conditional Probability
While both deal with probabilities of related events, they serve different purposes.
Conditional Probability simply asks: What is the chance of B happening, given that A has already happened? It's a direct calculation.
Bayes' Theorem works backward. It asks: Given that B has happened, what is the probability that A was the cause? It allows you to update your initial belief about A based on the new evidence of B.