Bayesian Probability Calculator
Calculate posterior probability using Bayes theorem from prior, likelihood, and evidence. Enter values for instant results with step-by-step formulas.
Reviewed for accuracy by Manoj Kumar, Mathematics Educator
Bayesian Probability Calculator
Calculator
Adjust values & calculateEnter your values below. Every result is computed in your browser โ no data is sent to any server.
Formula: P(A|B) = P(B|A) * P(A) / P(B)
Worked example โ Posterior probability = 16.10% (despite 95% test accuracy, only ~16% chance of disease)
Formula
P(A|B) = P(B|A) * P(A) / P(B)
Where P(A|B) is the posterior probability of hypothesis A given evidence B, P(B|A) is the likelihood (sensitivity), P(A) is the prior probability, and P(B) is the total probability of the evidence computed as P(B|A)*P(A) + P(B|not A)*P(not A).
Worked Examples
Example 1: Medical Screening Test Interpretation
Problem:A disease affects 1% of the population. A test has 95% sensitivity and 5% false positive rate. What is the probability of disease given a positive test?
Solution:P(Disease) = 0.01 (prior) P(Positive|Disease) = 0.95 (sensitivity) P(Positive|No Disease) = 0.05 (false positive rate) P(Positive) = 0.95 * 0.01 + 0.05 * 0.99 = 0.0095 + 0.0495 = 0.059 P(Disease|Positive) = (0.95 * 0.01) / 0.059 = 0.0095 / 0.059 = 0.1610
Result:Posterior probability = 16.10% (despite 95% test accuracy, only ~16% chance of disease)
Example 2: Spam Email Classification
Problem:5% of emails are spam. The word 'free' appears in 80% of spam and 10% of legitimate emails. What is the probability an email with 'free' is spam?
Solution:P(Spam) = 0.05 P('free'|Spam) = 0.80 P('free'|Not Spam) = 0.10 P('free') = 0.80 * 0.05 + 0.10 * 0.95 = 0.04 + 0.095 = 0.135 P(Spam|'free') = (0.80 * 0.05) / 0.135 = 0.04 / 0.135 = 0.2963
Result:P(Spam | contains 'free') = 29.63%
Frequently Asked Questions
What is the base rate fallacy and how does Bayes theorem address it?
The base rate fallacy occurs when people ignore the prior probability (base rate) of an event and focus only on the test accuracy. For example, if a disease affects 1 in 1000 people and a test is 99 percent accurate, many assume a positive test means 99 percent chance of having the disease. In reality, using Bayes theorem, the posterior probability is only about 9 percent because the vast majority of positive results are false positives from the 999 healthy people. Bayes theorem forces you to properly weight the prior probability against the test characteristics, preventing this common cognitive error that affects medical diagnosis, legal reasoning, and everyday decision making.
What are sensitivity and specificity in medical testing?
Sensitivity (true positive rate) is the probability that a test correctly identifies someone who has the condition, written as P(positive test | has disease). A sensitivity of 95 percent means the test catches 95 out of 100 truly sick people. Specificity (true negative rate) is the probability that a test correctly identifies someone who does not have the condition, written as P(negative test | no disease). Specificity of 95 percent means 95 out of 100 healthy people test negative. Both metrics are needed for Bayes theorem: sensitivity provides the likelihood, while the false positive rate (1 minus specificity) determines how many false alarms occur among the healthy population.
How do you interpret the posterior probability result?
The posterior probability represents your updated belief about the hypothesis after observing evidence. If the prior probability of disease was 1 percent and the posterior after a positive test is 16 percent, this means the positive test increased your probability estimate by a factor of 16 but the disease is still unlikely. A posterior above 50 percent means the hypothesis is more likely true than false given the evidence. In medical contexts, doctors often require very high posteriors (above 90 to 95 percent) before proceeding with invasive treatments. The magnitude of the update from prior to posterior depends on the likelihood ratio, which captures the diagnostic power of the test.
What is a likelihood ratio and why does it matter?
A likelihood ratio compares how likely the evidence is under the hypothesis versus under the alternative. The positive likelihood ratio (LR+) equals sensitivity divided by false positive rate. A positive LR of 19 means a positive test result is 19 times more likely in someone with the condition than without. The negative likelihood ratio (LR-) equals the false negative rate divided by specificity. Likelihood ratios are powerful because they capture the full diagnostic value of a test in a single number, independent of the base rate. An LR+ above 10 is considered strong evidence for the hypothesis, while an LR- below 0.1 is strong evidence against it.
How is Bayesian reasoning used in machine learning?
Bayesian methods are foundational in machine learning. Naive Bayes classifiers use Bayes theorem to classify emails as spam or not spam by combining prior spam frequency with word likelihoods. Bayesian neural networks maintain probability distributions over weights rather than point estimates, providing uncertainty quantification for predictions. Bayesian optimization efficiently searches hyperparameter spaces by building probabilistic models of the objective function. Gaussian processes, a Bayesian approach, provide confidence intervals with every prediction. Bayesian methods are especially valuable when data is scarce, when uncertainty matters for decision-making, and when combining expert knowledge (priors) with observed data in a principled framework.
Can Bayes theorem be applied iteratively with multiple pieces of evidence?
Yes, one of the most powerful features of Bayes theorem is that it can be applied sequentially. The posterior from one update becomes the prior for the next update when new evidence arrives. For example, after a positive screening test gives a posterior of 16 percent, a second confirmatory test can use 16 percent as the new prior. If the second test is also positive with different sensitivity and specificity, the resulting posterior might jump to 85 percent. This iterative updating is mathematically consistent and order-independent when the pieces of evidence are conditionally independent given the hypothesis. This property makes Bayesian reasoning ideal for sequential decision making and real-time data analysis.
What is the difference between Bayesian and frequentist statistics?
Frequentist statistics interprets probability as the long-run frequency of events and does not assign probabilities to hypotheses. It uses p-values and confidence intervals. Bayesian statistics treats probability as a degree of belief and directly computes the probability that a hypothesis is true given the data. Frequentists would say a 95 percent confidence interval has a 95 percent chance of containing the true value in repeated sampling, not that there is a 95 percent probability the true value is in any particular interval. Bayesians compute a 95 percent credible interval meaning there is a 95 percent probability the parameter lies within it. Bayesian methods require specifying prior distributions, which some see as subjective, while others view as a strength for incorporating domain knowledge.
How does prior probability selection affect Bayesian analysis?
The choice of prior significantly affects the posterior, especially with limited data. An informative prior based on domain knowledge (like disease prevalence from epidemiological studies) can improve accuracy when data is scarce. A non-informative or flat prior assigns equal probability to all possibilities, letting the data dominate the result. As more data accumulates, the influence of the prior diminishes and different reasonable priors converge to the same posterior, a property called Bayesian consistency. In practice, sensitivity analysis involves running the calculation with different priors to see how robust the conclusions are. When the prior and data strongly disagree, the posterior falls between them, weighted by relative information content.
What real-world scenarios benefit from Bayesian probability analysis?
Bayesian analysis is invaluable in many real-world scenarios. Medical screening programs use it to interpret test results given disease prevalence, helping doctors communicate accurate risk to patients. Forensic science applies it to DNA evidence evaluation, calculating the probability of guilt given a match. Insurance companies use Bayesian updating to adjust risk assessments as claims data accumulates. Search and rescue operations use it to update probability maps of a missing person location as areas are searched. Quality control in manufacturing uses Bayesian methods to determine defect rates. Spam filters, recommendation systems, and autonomous vehicles all rely on Bayesian reasoning to make decisions under uncertainty.
References
Reviewed for accuracy by Manoj Kumar, Mathematics Educator ยท Editorial policy
Related Calculators
๐ฒProbability Calculator
Calculate probability of events
๐งฎProbability of At Least Or Exactly Calculator
Calculate probability of at least or exactly with inputs, formulas, and instant results.
๐งฎBinomial Probability Calculator
Calculate binomial probability with inputs, formulas, and instant results.
๐งฎAnnulus Area Calculator
Calculate annulus area with inputs, formulas, and instant results.
๐งฎArea Calculator
Calculate area with inputs, formulas, and instant results.
๐งฎArea of a Rectangle Calculator
Calculate the area, perimeter, and diagonal of a rectangle. Find missing sides from known area. Convert between metric and imperial area units.
๐งฎArea of Crescent Calculator
Calculate area of crescent with inputs, formulas, and instant results.