Technopedia

The technologist’s encyclopedia

Conditional probability

Conditional probability quantifies how beliefs about events change when partial information is observed. It is the central operation in Bayesian updating, independence modeling, and the construction of conditional measures on refined information. It is relevant whenever a probability must be refined given a condition: medical diagnosis, spam filtering, reliability engineering, and probabilistic graphical models.

Authoritative sources

Definition

For events AA and BB with P(B)>0P(B) > 0:

P(A∣B)=P(A∩B)P(B)P(A \mid B) = \frac{P(A \cap B)}{P(B)}

The intuition: restrict the sample space to the outcomes in BB (the condition is known to hold), then renormalize so that the total probability on BB is 1. The event AA is now measured relative to the smaller world where BB has occurred.

Sample space Ω B A A∩B P(A|B) = P(A∩B) / P(B): the red region as a fraction of the blue region
Details

Step 1: The restriction idea.

Suppose you draw a card from a standard 52-card deck. Let AA = “the card is a King” and BB = “the card is a heart”. Without any information, P(A)=4/52=1/13P(A) = 4/52 = 1/13. Now you are told the card is a heart. The sample space shrinks to the 13 hearts. Among those, exactly one is a King, so P(A∣B)=1/13P(A \mid B) = 1/13.

Formally: P(A∩B)=1/52P(A \cap B) = 1/52 (the King of hearts), P(B)=13/52=1/4P(B) = 13/52 = 1/4, and indeed P(A∣B)=(1/52)/(1/4)=1/13P(A \mid B) = (1/52)/(1/4) = 1/13.

Step 2: Renormalization.

The division by P(B)P(B) is a renormalization. Before conditioning, the 13 hearts carry total mass 13/5213/52. After conditioning, they must carry total mass 1, so every probability inside BB is scaled up by 1/P(B)=41/P(B) = 4.

Step 3: When P(B)=0P(B) = 0.

The formula breaks down when P(B)=0P(B) = 0 (e.g. “the temperature is exactly 23.456 °C”). The remedy is the regular conditional probability, developed in the last section of this page. There, one replaces the quotient by a limit or by a measure-theoretic construction (Radon–Nikodým derivative).

Example problem.

Problem

A bag contains 3 red and 2 blue balls. You draw two balls without replacement. Let AA = “the second ball is red” and BB = “the first ball is red”. Compute P(A∣B)P(A \mid B).

Solution

After drawing a red ball first, the bag has 2 red and 2 blue. So P(A∣B)=2/4=1/2P(A \mid B) = 2/4 = 1/2.

Check with the formula: P(A∩B)=(3/5)(2/4)=3/10P(A \cap B) = (3/5)(2/4) = 3/10, P(B)=3/5P(B) = 3/5, so P(A∣B)=(3/10)/(3/5)=1/2P(A \mid B) = (3/10)/(3/5) = 1/2. ✓

Independence

Events AA and BB are independent iff P(A∩B)=P(A) P(B)P(A \cap B) = P(A)\,P(B).

Random variables XX and YY are independent iff their joint distribution factors: P(X∈A, Y∈B)=P(X∈A) P(Y∈B)P(X \in A,\, Y \in B) = P(X \in A)\, P(Y \in B) for all measurable sets A,BA, B.

Mutual independence of X1,…,XnX_1, \ldots, X_n requires the joint to factor for every subset: P(Xi1∈A1,…,Xik∈Ak)=∏jP(Xij∈Aj)P(X_{i_1} \in A_1, \ldots, X_{i_k} \in A_k) = \prod_j P(X_{i_j} \in A_j).

Details

Step 1: Independence as a structural property.

Independence is a statement about the joint measure, not about moments. Two variables can have zero covariance yet be strongly dependent.

Worked example. Let X∼Unif[0,2π]X \sim \text{Unif}[0, 2\pi] and Y=sin⁡(X)Y = \sin(X). Then:

Yet YY is a deterministic function of XX, so knowing XX determines YY exactly. The variables are maximally dependent despite zero covariance.

Y = sin(X) for X ∈ [0, 2π] X Y Cov(X, sin X) = 0, yet Y is determined by X

Step 2: Conditional independence.

X⊥ ⁣ ⁣⊥Y∣ZX \perp\!\!\perp Y \mid Z means P(X∈A,Y∈B∣Z)=P(X∈A∣Z) P(Y∈B∣Z)P(X \in A, Y \in B \mid Z) = P(X \in A \mid Z)\, P(Y \in B \mid Z) almost surely. This is the key relation in Bayesian networks and hidden Markov models (see Stochastic processes).

Step 3: Mutual vs. pairwise independence.

Pairwise independence (every pair is independent) does not imply mutual independence. Classic counterexample: let X1,X2X_1, X_2 be independent Rademacher (±1 with equal probability) and set X3=X1X2X_3 = X_1 X_2. Then every pair is independent, but X1X2X3=1X_1 X_2 X_3 = 1 always, so the triple is not mutually independent.

Example problem.

Problem

Two fair coins are flipped. Let AA = “at least one head”, BB = “the first coin is heads”. Are AA and BB independent?

Solution

P(A)=3/4P(A) = 3/4, P(B)=1/2P(B) = 1/2, P(A∩B)=P(first is H)=1/2P(A \cap B) = P(\text{first is H}) = 1/2 (since if the first is H, A is automatically satisfied).

Check: P(A) P(B)=(3/4)(1/2)=3/8≠1/2=P(A∩B)P(A)\,P(B) = (3/4)(1/2) = 3/8 \neq 1/2 = P(A \cap B). Not independent. ✓

Bayes’ theorem

For events AA and BB with P(B)>0P(B) > 0, the law of total probability states that for any partition {Ai}\{A_i\} of the sample space:

P(B)=∑iP(B∣Ai) P(Ai)P(B) = \sum_i P(B \mid A_i)\, P(A_i)

Substituting this into the definition gives Bayes’ theorem:

P(A∣B)=P(B∣A) P(A)P(B)=P(B∣A) P(A)∑iP(B∣Ai) P(Ai)P(A \mid B) = \frac{P(B \mid A)\, P(A)}{P(B)} = \frac{P(B \mid A)\, P(A)}{\sum_i P(B \mid A_i)\, P(A_i)}

This is a pure algebraic identity: it inverts the direction of conditioning. In the continuous case, densities replace probabilities:

fX∣Y(x∣y)=fY∣X(y∣x) fX(x)fY(y)f_{X \mid Y}(x \mid y) = \frac{f_{Y \mid X}(y \mid x)\, f_X(x)}{f_Y(y)}

The full Bayesian framework—priors, likelihoods, posteriors, conjugate families, MCMC—is developed in Bayesian inference.

Details

Step 1: The algebraic inversion.

Bayes’ theorem converts P(B∣A)P(B \mid A) (how the data looks given a hypothesis) into P(A∣B)P(A \mid B) (how plausible the hypothesis is given the data). The numerator is the joint P(A∩B)=P(B∣A) P(A)=P(A∣B) P(B)P(A \cap B) = P(B \mid A)\,P(A) = P(A \mid B)\,P(B), and the theorem simply solves for P(A∣B)P(A \mid B).

Step 2: The base-rate fallacy.

A common error is to ignore the prior P(A)P(A) and treat the likelihood P(B∣A)P(B \mid A) as the posterior. When the prior is very small, the posterior can be far smaller than the likelihood suggests. The interactive simulation above makes this tangible: set the prior to 0.001 and the sensitivity to 0.99, and watch the posterior stay near 2% even with a 99% sensitive test.

Step 3: The law of total probability as a partition identity.

The denominator P(B)=∑iP(B∣Ai) P(Ai)P(B) = \sum_i P(B \mid A_i)\,P(A_i) is not a separate theorem; it is the definition of P(B)P(B) expanded over a partition. For a binary partition {A,Ac}\{A, A^c\}: P(B)=P(B∣A) P(A)+P(B∣Ac) P(Ac)P(B) = P(B \mid A)\,P(A) + P(B \mid A^c)\,P(A^c).

Worked example (disease screening).

A disease affects 1 in 10 000 people. A test has sensitivity 99% and specificity 99.5%. A patient tests positive. What is the probability the patient actually has the disease?

Let DD = has disease, TT = tests positive.

P(D∣T)=P(T∣D) P(D)P(T∣D) P(D)+P(T∣Dc) P(Dc)P(D \mid T) = \frac{P(T \mid D)\,P(D)}{P(T \mid D)\,P(D) + P(T \mid D^c)\,P(D^c)} =0.99×10−40.99×10−4+0.005×0.9999≈9.9×10−59.9×10−5+4.9995×10−3≈0.0194= \frac{0.99 \times 10^{-4}}{0.99 \times 10^{-4} + 0.005 \times 0.9999} \approx \frac{9.9 \times 10^{-5}}{9.9 \times 10^{-5} + 4.9995 \times 10^{-3}} \approx 0.0194

Despite a positive test, the probability of disease is only about 2%. The low prior (base rate) dominates.

Probability tree: 10 000-person population 10 000 P(D)=0.0001 10 P(D^c)=0.9999 9 990 P(T|D)=0.99 ≈9.9 P(T^c|D)=0.01 ≈0.1 P(T|D^c)=0.005 ≈49.95 P(T^c|D^c)=0.995 ≈9 940 Positive tests: ≈ 9.9 + 49.95 ≈ 59.85 P(D|T) ≈ 9.9/59.85 ≈ 0.0194 ≈ 2% Only ~2% of positive tests are true positives

Example problem.

Problem

A factory has two machines: Machine A produces 60% of widgets and has a 2% defect rate. Machine B produces 40% of widgets and has a 5% defect rate. A widget is found to be defective. What is the probability it came from Machine A?

Solution

Let AA = from Machine A, DD = defective.

P(A)=0.6P(A) = 0.6, P(D∣A)=0.02P(D \mid A) = 0.02, P(D∣Ac)=0.05P(D \mid A^c) = 0.05.

P(A∣D)=0.02×0.60.02×0.6+0.05×0.4=0.0120.012+0.02=0.0120.032=0.375P(A \mid D) = \frac{0.02 \times 0.6}{0.02 \times 0.6 + 0.05 \times 0.4} = \frac{0.012}{0.012 + 0.02} = \frac{0.012}{0.032} = 0.375

So there is a 37.5% chance the defective widget came from Machine A, despite Machine A producing most of the output. Machine B’s higher defect rate pulls the posterior toward B.

Chain rule

For a sequence of random variables X1,…,XnX_1, \ldots, X_n:

P(X1,…,Xn)=∏i=1nP(Xi∣X1,…,Xi−1)P(X_1, \ldots, X_n) = \prod_{i=1}^{n} P(X_i \mid X_1, \ldots, X_{i-1})

This factorization is the basis of autoregressive models, language models, and sequential Monte Carlo (see Stochastic processes).

Details

Step 1: Derivation from the definition.

The chain rule follows by repeated application of P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B)/P(B). For three variables:

P(X1,X2,X3)=P(X1) P(X2∣X1) P(X3∣X1,X2)P(X_1, X_2, X_3) = P(X_1)\, P(X_2 \mid X_1)\, P(X_3 \mid X_1, X_2)

Each step peels off one variable by conditioning on all previous ones.

Step 2: The continuous case.

For joint densities: f(x1,…,xn)=∏if(xi∣x1,…,xi−1)f(x_1, \ldots, x_n) = \prod_i f(x_i \mid x_1, \ldots, x_{i-1}). This is the form used in autoregressive models and in the sequential factorization of language models.

Step 3: Ordering matters for compactness.

The ordering is arbitrary; different orderings give different factorizations of the same joint. Choosing an ordering that matches the causal or temporal structure of the problem yields the most compact model. For example, in a Markov chain, the temporal ordering gives P(x1,…,xn)=P(x1)∏iP(xi∣xi−1)P(x_1, \ldots, x_n) = P(x_1)\prod_i P(x_i \mid x_{i-1}), a product of nn one-step transitions rather than nn full-history conditionals.

Example problem.

Problem

A three-letter word is generated by: first letter uniform over {A, B}, second letter is A with probability 0.8 if the first is A, else B with probability 0.7. Third letter is always the same as the second. Write the joint probability of the word “ABA” using the chain rule.

Solution P(A,B,A)=P(A) P(B∣A) P(A∣A,B)P(A, B, A) = P(A)\, P(B \mid A)\, P(A \mid A, B)
  • P(A)=1/2P(A) = 1/2
  • P(B∣A)=1−0.8=0.2P(B \mid A) = 1 - 0.8 = 0.2
  • P(A∣A,B)=0P(A \mid A, B) = 0 (third letter equals second, which is B, so it cannot be A)

So P(A,B,A)=0P(A, B, A) = 0. The word is impossible under this model.

Regular conditional probability

Given a sigma-algebra G⊆F\mathcal{G} \subseteq \mathcal{F}, the conditional probability P(A∣G)P(A \mid \mathcal{G}) is the unique (a.s.) G\mathcal{G}-measurable random variable satisfying

∫BP(A∣G) dP=P(A∩B)∀B∈G\int_B P(A \mid \mathcal{G})\, dP = P(A \cap B) \quad \forall B \in \mathcal{G}

This is the “integral version” of the elementary definition: just as P(A∣B)=P(A∩B)/P(B)P(A \mid B) = P(A \cap B)/P(B) is the unique number on BB whose average (weighted by PP) reproduces P(A∩B)P(A \cap B), the random variable P(A∣G)P(A \mid \mathcal{G}) is the unique G\mathcal{G}-measurable function whose integral over every B∈GB \in \mathcal{G} reproduces P(A∩B)P(A \cap B). The same construction, with PP replaced by the integral of a random variable XX, gives the conditional expectation E[X∣G]\mathbb{E}[X \mid \mathcal{G}] (see Random variables and expectation).

Details

Step 1: The discrete case.

When G\mathcal{G} is generated by a discrete random variable YY with values y1,…,yky_1, \ldots, y_k, the regular conditional probability reduces to the familiar formula:

P(A∣Y=yi)=P(A∩{Y=yi})P(Y=yi)P(A \mid Y = y_i) = \frac{P(A \cap \{Y = y_i\})}{P(Y = y_i)}

The random variable P(A∣G)P(A \mid \mathcal{G}) simply takes the value P(A∣Y=yi)P(A \mid Y = y_i) on the set {Y=yi}\{Y = y_i\}.

Step 2: The continuous case.

In the continuous case, a regular conditional probability P(A∣Y=y)P(A \mid Y = y) exists as a probability kernel y↦P(⋅∣Y=y)y \mapsto P(\cdot \mid Y = y) under mild conditions (standard Borel spaces). This is the object that makes Bayesian updating rigorous when the observation is continuous. The construction uses the Radon–Nikodým theorem: the measure μ(B)=P(A∩B)\mu(B) = P(A \cap B) is absolutely continuous with respect to ν(B)=P(B)\nu(B) = P(B) on G\mathcal{G}, and the RN derivative is P(A∣G)P(A \mid \mathcal{G}).

Step 3: Connection to conditional expectation.

The conditional expectation E[X∣G]\mathbb{E}[X \mid \mathcal{G}] is defined identically, with P(A∩B)P(A \cap B) replaced by ∫BX dP\int_B X\, dP. It is the “integral version” of conditional probability: where P(A∣G)P(A \mid \mathcal{G}) answers “what is the probability of AA given the information in G\mathcal{G}?”, E[X∣G]\mathbb{E}[X \mid \mathcal{G}] answers “what is the best G\mathcal{G}-measurable guess of XX?”. See Random variables and expectation for the full development.

Example problem.

Problem

Let X∼Unif[0,1]X \sim \text{Unif}[0, 1] and let G=σ({X<1/2})\mathcal{G} = \sigma(\{X < 1/2\}). Compute P(X>3/4∣G)P(X > 3/4 \mid \mathcal{G}).

Solution

G\mathcal{G} has two atoms: {X<1/2}\{X < 1/2\} and {X≥1/2}\{X \geq 1/2\}.

  • On {X<1/2}\{X < 1/2\}: P(X>3/4∣X<1/2)=0P(X > 3/4 \mid X < 1/2) = 0 (impossible).
  • On {X≥1/2}\{X \geq 1/2\}: P(X>3/4∣X≥1/2)=P(X>3/4)/P(X≥1/2)=(1/4)/(1/2)=1/2P(X > 3/4 \mid X \geq 1/2) = P(X > 3/4)/P(X \geq 1/2) = (1/4)/(1/2) = 1/2.

So P(X>3/4∣G)=0⋅1{X<1/2}+(1/2)⋅1{X≥1/2}P(X > 3/4 \mid \mathcal{G}) = 0 \cdot \mathbf{1}_{\{X < 1/2\}} + (1/2) \cdot \mathbf{1}_{\{X \geq 1/2\}}.

Quizz

Quizz

A disease affects 1 in 10 000 people. A test has sensitivity 99% and specificity 99.5%. A patient tests positive. What is the probability the patient actually has the disease?

Solution

Let DD = has disease, TT = tests positive.

  • Prior: P(D)=10−4P(D) = 10^{-4}
  • Sensitivity: P(T∣D)=0.99P(T \mid D) = 0.99
  • False-positive rate: P(T∣Dc)=0.005P(T \mid D^c) = 0.005

By Bayes’ theorem:

P(D∣T)=P(T∣D) P(D)P(T∣D) P(D)+P(T∣Dc) P(Dc)P(D \mid T) = \frac{P(T \mid D)\,P(D)}{P(T \mid D)\,P(D) + P(T \mid D^c)\,P(D^c)} =0.99×10−40.99×10−4+0.005×0.9999≈9.9×10−59.9×10−5+4.9995×10−3≈0.0194= \frac{0.99 \times 10^{-4}}{0.99 \times 10^{-4} + 0.005 \times 0.9999} \approx \frac{9.9 \times 10^{-5}}{9.9 \times 10^{-5} + 4.9995 \times 10^{-3}} \approx 0.0194

Despite a positive test, the probability of disease is only about 2%. The low prior (base rate) dominates. This is the base-rate fallacy in action.

Probability tree: 10 000-person population 10 000 P(D)=0.0001 10 P(D^c)=0.9999 9 990 P(T|D)=0.99 ≈9.9 P(T^c|D)=0.01 ≈0.1 P(T|D^c)=0.005 ≈49.95 P(T^c|D^c)=0.995 ≈9 940 Positive tests: ≈ 9.9 + 49.95 ≈ 59.85 P(D|T) ≈ 9.9/59.85 ≈ 0.0194 ≈ 2% Only ~2% of positive tests are true positives