Tool to calculate conditional probability, apply the formula P(A|B), use Bayes' theorem and calculate the relationships between events.
Conditional Probability - dCode
Tag(s) : Combinatorics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
Conditional probability measures the probability that an event $ A $ occurs given that another event $ B $ has already occurred. It is denoted $ P(A|B) $, read as probability of A given B, and is calculated using the formula:
$$ P(A|B) = \frac{P(A \cap B)}{P(B)} $$
where $ P(A \cap B) $ is the probability that $ A $ and $ B $ occur simultaneously, and $ P(B) $ is the probability that $ B $ occurs (a probability that cannot be zero).
Intuitive interpretation: conditioning by $ B $ means restricting the set of possibilities to the single case where $ B $ is true, and then measuring the frequency of $ A $ in this new set.
Bayes' theorem reformulates a conditional probability by inverting the condition:
$$ P(B|A) = \frac{P(A|B) \cdot P(B)}{P(A)} $$
Bayesian inference allows us to calculate B given A from A given B, and vice versa.
Conditional probabilities are used to integrate available information into the calculation. They allow to:
— update a hypothesis in light of new data (medical tests, diagnoses, forecasts);
— model dependencies between events;
— avoid misinterpretations by distinguishing between correlation and causation.
Example: If $ P(🌧) = 0.2 $ but $ P(🌧|☁) = 0.7 $, then observing clouds (☁) significantly alters the assessment of the risk of rain (🌧).
The conditional probability $ P(A|B) $ is the probability of $ A $ occurring under the condition that $ B $ occurs.
The joint probability $ P(A\cap B) $ is the probability that $ A $ and $ B $ occur together, without any prior condition.
These two probabilities are related by the formula: $$ P(A|B) \cdot P(B) = P(A \cap B) $$
The two probabilities $ P(A|B) $ and $ P(B|A) $ are generally different and often mistakenly confused.
Example: P(🤢|☑): probability of being ill if the test is positive (value generally sought by a patient or doctor)
Example: P(☑|🤢): probability of a positive test if the patient is ill: a measure of the test's sensitivity (value of interest to test manufacturers)
Two events $ A $ and $ B $ are independent if the occurrence of the first does not change the probability of the other, that is, if $ P(A|B) = P(A) $ or, equivalently, $ P(A \cap B) = P(A) \cdot P(B) $
This independence is symmetric and also implies $ P(B|A) = P(B) $
Example: When rolling two fair dice, the result of the first die does not influence that of the second.
dCode retains ownership of the "Conditional Probability" source code. Any algorithm for the "Conditional Probability" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Conditional Probability" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Conditional Probability" or any other element are not public (except explicit open source licence). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Conditional Probability" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source (Creative Commons CC-BY free distribution license).
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Conditional Probability on dCode.fr [online website], retrieved on 2026-02-04,