Conditional Probability, Independence & Bayes

Study Sheet

Conditional Probability, Independence & Bayes

Competition counting & probability, Unit 8

Conditional Probability P(A∣B)P(A\mid B)

Concept
Probability once you already know something

The conditional probability of AA given that BB has occurred is

P(A∣B)=P(A∩B)P(B),P(B)>0.P(A\mid B) = \frac{P(A\cap B)}{P(B)}, \qquad P(B) > 0.

Conditioning on BB shrinks the sample space to just the outcomes in BB: we ask what fraction of BB's probability also lies in AA. Rearranging gives the form you will use constantly,

P(A∩B)=P(A∣B) P(B)=P(B∣A) P(A).P(A\cap B) = P(A\mid B)\,P(B) = P(B\mid A)\,P(A).

In a finite equally-likely setting this is simply P(A∣B)=∣A∩B∣∣B∣P(A\mid B) = \dfrac{|A\cap B|}{|B|}: recount inside the restricted world BB.

Conditional probability P(A∣B)P(A\mid B) restricts attention to the outcomes where BB happened and asks what fraction of those are in AA. Independence means the condition changes nothing: P(A∣B)=P(A)P(A\mid B) = P(A), equivalently P(A∩B)=P(A)P(B)P(A\cap B) = P(A)P(B). Bayes' theorem reverses a conditional — from "probability of a positive test given the disease" to "probability of the disease given a positive test".

Example
Worked example: a die given “even”
123456A = greater than 3B = even (shaded): the new sample spaceinside B, A holds for 4 and 6: 2 of 3
Conditioning on "even" discards 1,3,51, 3, 5; the question is then asked inside {2,4,6}\{2, 4, 6\}.

A fair die is rolled. Given that the result is even, what is the probability it is greater than 33?

Solution. Let B={2,4,6}B=\{2,4,6\} and A={4,5,6}A=\{4,5,6\}. Then A∩B={4,6}A\cap B=\{4,6\}, so

P(A∣B)=∣A∩B∣∣B∣=23.P(A\mid B) = \frac{|A\cap B|}{|B|} = \frac{2}{3}.

Knowing “even” throws away the odd outcomes; we only compare within {2,4,6}\{2,4,6\}.

Side note
Where it goes wrong

Confusing P(A∣B)P(A\mid B) with P(B∣A)P(B\mid A). The probability that a test is positive given the disease is not the probability of the disease given a positive test — the base rate matters enormously.

Example
Worked example: two cards without replacement

Two cards are drawn from a standard 5252-card deck without replacement. What is the probability the second is a heart given the first was a heart?

Solution. After removing one heart, 1212 hearts remain among 5151 cards, so

P(2nd heart∣1st heart)=1251=417.P(\text{2nd heart}\mid\text{1st heart}) = \frac{12}{51} = \frac{4}{17}.

Conditioning literally updates the deck.

Tip

Pitfall. P(A∣B)P(A\mid B) and P(B∣A)P(B\mid A) are different numbers. “The probability of a rash given measles” is near 11; “the probability of measles given a rash” is tiny. Swapping the two is the single most common conditional-probability error.

Try it
Quick check

A fair die is rolled. Given that the result is even, find the probability that it is a 22.

Work it on paper before revealing the answer.

Show the answer

Answer: Method: conditional probability P(A∣B)=P(A∩B)P(B)P(A\mid B)=\dfrac{P(A\cap B)}{P(B)}. Condition on the die being even, so the sample space shrinks to {2,4,6}\{2,4,6\}, three equally likely outcomes. Exactly one of them is a 22. Formally, with A={2}A=\{2\} and B={2,4,6}B=\{2,4,6\},

P(A∣B)=P(A∩B)P(B)=1/63/6=13.P(A\mid B)=\frac{P(A\cap B)}{P(B)}=\frac{1/6}{3/6}=\boxed{\dfrac13}.

The Multiplication Rule & Probability Trees

Concept
Chaining conditional probabilities

Solving P(A∣B)=P(A∩B)P(B)P(A\mid B)=\frac{P(A\cap B)}{P(B)} for the intersection gives the multiplication rule:

P(A∩B)=P(B) P(A∣B).P(A\cap B) = P(B)\,P(A\mid B).

For a sequence of stages it chains (the chain rule):

P(A1∩A2∩A3)=P(A1) P(A2∣A1) P(A3∣A1∩A2).P(A_1\cap A_2\cap A_3) = P(A_1)\,P(A_2\mid A_1)\,P(A_3\mid A_1\cap A_2).

A probability tree draws this: each branch carries a conditional probability, and the probability of a full path is the product of the branch probabilities along it. Probabilities on branches leaving a node sum to 11; probabilities of the leaves sum to 11.

Reminder — The differentiation rules:  (xn)′=nxn−1,(fg)′=f′g+fg′,(fg)′=f′g−fg′g2,(f(g(x)))′=f′(g(x))g′(x)(x^{n})'=nx^{n-1},\quad (fg)'=f'g+fg',\quad \left(\tfrac{f}{g}\right)'=\frac{f'g-fg'}{g^{2}},\quad \big(f(g(x))\big)'=f'(g(x))g'(x)

Multiply along a path for a leaf; add leaves for an event. The tree is the two-stage example below: 22 red and 33 blue balls, two draws without replacement.

Example
Worked example: drawing two aces

Two cards are drawn without replacement. Probability both are aces?

Solution. Multiply along the path:

P(ace1∩ace2)=452⋅351=122652=1221.P(\text{ace}_1\cap\text{ace}_2) = \frac{4}{52}\cdot\frac{3}{51} = \frac{12}{2652} = \frac{1}{221}.
Example
Worked example: reading a two-stage tree

A box has 22 red and 33 blue balls. Draw two without replacement. Probability of exactly one red?

Solution. Two paths give “one red”: RB and BR.

P=25⋅34⏟RB+35⋅24⏟BR=620+620=1220=35.P = \underbrace{\frac{2}{5}\cdot\frac{3}{4}}_{RB} + \underbrace{\frac{3}{5}\cdot\frac{2}{4}}_{BR} = \frac{6}{20}+\frac{6}{20} = \frac{12}{20} = \frac{3}{5}.

Multiply along each path, then add the paths that satisfy the event.

Tip

Tip. Trees turn “and” into multiplication and “or” into addition automatically. Whenever a problem unfolds in stages (draw, then draw; test, then confirm), sketch the tree before writing any algebra.

Try it
Quick check

A box has 33 red and 22 blue balls. Two are drawn without replacement. Find the probability that they are the same colour.

Work it on paper before revealing the answer.

Show the answer

Answer: Two leaves of the tree: red-red 35⋅24=620\tfrac35\cdot\tfrac24 = \tfrac{6}{20} and blue-blue 25⋅14=220\tfrac25\cdot\tfrac14 = \tfrac{2}{20}. Add them: 820=25\tfrac{8}{20} = \boxed{\tfrac25}.

Independence

Concept
When knowing BB tells you nothing about AA

Events AA and BB are independent exactly when

P(A∩B)=P(A) P(B),P(A\cap B) = P(A)\,P(B),

equivalently (when the conditionals are defined) P(A∣B)=P(A)P(A\mid B) = P(A) and P(B∣A)=P(B)P(B\mid A)=P(B). Learning that BB happened does not change the probability of AA.

For several events, mutual independence requires the product rule to hold for every subcollection, not just pairs. Pairwise independence does not imply mutual independence.

Example
Worked example: independent vs. dependent draws

Draw a card, replace it, reshuffle, draw again. Are “first is a heart” and “second is a heart” independent?

Solution. With replacement the deck resets: P(2nd heart∣1st heart)=14=P(2nd heart)P(\text{2nd heart}\mid\text{1st heart}) = \tfrac14 = P(\text{2nd heart}), so yes. Without replacement it was 1251≠14\tfrac{12}{51}\neq\tfrac14, so no. Replacement is the usual switch between independent and dependent.

Example
Worked example: testing the definition
123456123456first diesecondA: first die ≤ 212 cellsB: sum 76 cellsboth: 2 cells= 36 × 1/3 × 1/6
B takes up the same share (16\tfrac16) of the strip A as of the whole grid: that is independence.

Roll two fair dice. Let A=A= “first die is ≤2\le 2” and B=B= “sum is 77”. Independent?

Solution. P(A)=26=13P(A)=\tfrac{2}{6}=\tfrac13, P(B)=636=16P(B)=\tfrac{6}{36}=\tfrac16. The pairs with first die ≤2\le 2 and sum 77 are (1,6),(2,5)(1,6),(2,5), so P(A∩B)=236=118P(A\cap B)=\tfrac{2}{36}=\tfrac{1}{18}. Check: P(A)P(B)=13⋅16=118P(A)P(B)=\tfrac13\cdot\tfrac16=\tfrac{1}{18}. Equal, so independent.

Tip

Pitfall. Independent is not the same as mutually exclusive. Disjoint events with positive probability are strongly dependent: if A∩B=∅A\cap B=\varnothing then P(A∣B)=0≠P(A)P(A\mid B)=0\neq P(A). Always test independence with the product rule, never by intuition.

Try it
Quick check

Two fair coins are flipped. Given that at least one shows heads, find the probability that both show heads.

Work it on paper before revealing the answer.

Show the answer

Answer: Conditional probability. The four equally likely flips are {HH,HT,TH,TT}\{HH,HT,TH,TT\}. Conditioning on “at least one head” removes TTTT, leaving 33 outcomes. Only HHHH gives two heads:

P(both∣at least one)=P(HH)P(HH)+P(HT)+P(TH)=1/43/4=13.P(\text{both}\mid \text{at least one}) = \frac{P(HH)}{P(HH)+P(HT)+P(TH)} = \frac{1/4}{3/4} = \boxed{\dfrac13}.

The Law of Total Probability

Concept
Break an event across a partition of causes

Let B1,B2,…,BnB_1,B_2,\dots,B_n partition the sample space (disjoint, together all outcomes, each P(Bi)>0P(B_i)>0). For any event AA,

P(A)=∑i=1nP(A∣Bi) P(Bi).P(A) = \sum_{i=1}^{n} P(A\mid B_i)\,P(B_i).

Each term is one path of a tree: choose the scenario BiB_i, then let AA happen inside it. This is the workhorse for computing an overall probability when the world splits into cases.

Example
Worked example: two urns

Urn 1 has 33 red, 11 white; Urn 2 has 11 red, 33 white. Flip a fair coin to pick an urn, then draw a ball. Probability the ball is red?

Solution. Partition by the urn:

P(R)=P(R∣U1)P(U1)+P(R∣U2)P(U2)=34⋅12+14⋅12=38+18=12.P(R) = P(R\mid U_1)P(U_1) + P(R\mid U_2)P(U_2) = \frac34\cdot\frac12 + \frac14\cdot\frac12 = \frac{3}{8}+\frac{1}{8} = \frac12.
Example
Worked example: defective parts from three machines
0.50.01D0.0050.99ok0.495A0.30.02D0.0060.98ok0.294B0.20.03D0.0060.97ok0.194C
The three DD leaves add to 0.005+0.006+0.006=0.0170.005 + 0.006 + 0.006 = 0.017.

Machines A, B, C make 50%,30%,20%50\%, 30\%, 20\% of output with defect rates 1%,2%,3%1\%, 2\%, 3\%. Probability a random item is defective?

Solution.

P(D)=(0.01)(0.50)+(0.02)(0.30)+(0.03)(0.20)=0.005+0.006+0.006=0.017.P(D) = (0.01)(0.50) + (0.02)(0.30) + (0.03)(0.20) = 0.005 + 0.006 + 0.006 = 0.017.

A weighted average of the defect rates, weighted by production share.

Tip

Tip. The weights P(Bi)P(B_i) must sum to 11 and the cases must not overlap. When you see “there are several types/sources, each with its own rate,” reach for total probability.

Try it
Quick check

Urn 1 holds 22 red and 22 white balls; urn 2 holds 11 red and 33 white. An urn is chosen, urn 1 with probability 13\tfrac13 and urn 2 with probability 23\tfrac23, and a ball is drawn from it. Find P(red)P(\text{red}).

Work it on paper before revealing the answer.

Show the answer

Answer: Split by urn:

P(R)=13⋅24+23⋅14=16+16=13.P(R) = \tfrac13\cdot\tfrac24 + \tfrac23\cdot\tfrac14 = \tfrac16 + \tfrac16 = \boxed{\tfrac13}.

Bayes' Theorem

Concept
Reversing the conditioning

Combining P(Bi∩A)=P(A∣Bi)P(Bi)P(B_i\cap A)=P(A\mid B_i)P(B_i) with the law of total probability gives Bayes' Theorem:

P(Bi∣A)=P(A∣Bi) P(Bi)∑jP(A∣Bj) P(Bj)=P(A∣Bi) P(Bi)P(A).P(B_i\mid A) = \frac{P(A\mid B_i)\,P(B_i)}{\displaystyle\sum_{j} P(A\mid B_j)\,P(B_j)} = \frac{P(A\mid B_i)\,P(B_i)}{P(A)}.

It converts the prior P(Bi)P(B_i) (belief before the evidence) into the posterior P(Bi∣A)P(B_i\mid A) (belief after seeing AA). The numerator is one path; the denominator is all paths reaching AA.

Example
Worked example: which urn produced the red ball?

Using the two-urn setup above, a red ball was drawn. Probability it came from Urn 1?

Solution.

P(U1∣R)=P(R∣U1)P(U1)P(R)=34⋅1212=3/81/2=34.P(U_1\mid R) = \frac{P(R\mid U_1)P(U_1)}{P(R)} = \frac{\frac34\cdot\frac12}{\frac12} = \frac{3/8}{1/2} = \frac34.

The red ball is evidence that shifts belief toward the red-heavy urn.

Example
Worked example: the defective came from machine C?
A: 5B: 6C: 6defective items per 1000 made: 17P(C | defective) = 6/17
Conditioning on "defective" keeps only the 1717 defective items in each 10001000; machine C made 66 of them.

For the three machines above, a defective item is found. Probability it was machine C's?

Solution.

P(C∣D)=(0.03)(0.20)0.017=0.0060.017=617≈0.353.P(C\mid D) = \frac{(0.03)(0.20)}{0.017} = \frac{0.006}{0.017} = \frac{6}{17} \approx 0.353.

Even though C makes only 20%20\% of output, its high defect rate makes it responsible for over a third of defects.

Side note
Where it goes wrong

Answering with the likelihood instead of the posterior. "Machine C's defect rate is 3%3\%, so the chance a defective came from C is 0.030.03" swaps P(D∣C)P(D\mid C) for P(C∣D)P(C\mid D). The first is a fraction of C's output; the second is a fraction of the defective pile, 617≈0.353\tfrac{6}{17} \approx 0.353. Ask which group the fraction is taken of.

Tip

Tip. A clean recipe: (1) list the scenarios BiB_i and their priors, (2) attach the likelihood P(A∣Bi)P(A\mid B_i) to each, (3) multiply for each path, (4) divide the target path by the sum of all paths. Steps 1–3 are just a tree; Bayes is only the final division.

Try it
Quick check

In the urn problem (urn 1: 22 red, 22 white, chosen with probability 13\tfrac13; urn 2: 11 red, 33 white, chosen with probability 23\tfrac23), a red ball is drawn. Find the probability it came from urn 1.

Work it on paper before revealing the answer.

Show the answer

Answer: The two paths to red are urn 1 then red, 13⋅12=16\tfrac13\cdot\tfrac12 = \tfrac16, and urn 2 then red, 23⋅14=16\tfrac23\cdot\tfrac14 = \tfrac16. Bayes divides the first by their sum:

P(U1∣R)=1/61/6+1/6=12.P(U_1\mid R) = \frac{1/6}{1/6 + 1/6} = \boxed{\tfrac12}.

Urn 1 is richer in red, but it is chosen half as often; the two effects cancel exactly.

Classic Traps: Monty Hall, Two-Child, False Positives

Concept
Why these fool everyone

Each trap hides a conditioning step. The intuition “symmetry means 50/5050/50” fails because the evidence is not symmetric across the hidden scenarios. Draw the tree, weight by priors, and let Bayes overrule the gut.

Example
Monty Hall, fully explained

Three doors hide one car and two goats. You pick a door; the host — who knows where the car is — opens a different door revealing a goat, then offers a switch. Should you switch?

Solution. Your first pick is right with probability 13\tfrac13 and wrong with probability 23\tfrac23. The host's guaranteed goat-reveal gives no new information about your original door, so:

  • If you initially picked the car (13\tfrac13), switching loses.
  • If you initially picked a goat (23\tfrac23), the host is forced to reveal the other goat, so the remaining door hides the car — switching wins.

Therefore P(win by switching)=23P(\text{win by switching}) = \tfrac23, double the 13\tfrac13 from staying. The key is that the host's choice is constrained by knowledge; a host opening a random door would change the analysis.

Example
The false-positive (medical-test) paradox
0.1%99%99 +1 −100 ill99.9%1%999 +98901 −99900 well100000positives: 99 + 999 = 1098, of whom 99 are ill
The same test on 100000100000 people: the 999999 false positives from the healthy crowd swamp the 9999 true ones.

A disease affects 11 in 10001000 people. A test is 99%99\% accurate both ways (sensitivity 99%99\%, specificity 99%99\%). You test positive. What is the probability you actually have the disease?

Solution. Let DD be disease, ++ a positive test. Priors P(D)=0.001P(D)=0.001, P(Dc)=0.999P(D^c)=0.999.

P(+∣D)=0.99,P(+∣Dc)=0.01.P(+\mid D)=0.99,\qquad P(+\mid D^c)=0.01.

By Bayes,

P(D∣+)=(0.99)(0.001)(0.99)(0.001)+(0.01)(0.999)=0.000990.00099+0.00999=0.000990.01098≈0.090.P(D\mid +) = \frac{(0.99)(0.001)}{(0.99)(0.001)+(0.01)(0.999)} = \frac{0.00099}{0.00099+0.00999} = \frac{0.00099}{0.01098} \approx 0.090.

Only about 9%9\%! Because the disease is rare, the many false positives from the huge healthy population swamp the few true positives. The base rate dominates.

Example
The two-child problem and its ambiguity

A family has two children.

  • “At least one is a boy.” Probability both are boys? Sample space {BB,BG,GB,GG}\{BB,BG,GB,GG\} is equally likely; condition on at least one boy: {BB,BG,GB}\{BB,BG,GB\}, of which BBBB is one. Answer 13\tfrac13.
  • “The older is a boy.” Probability both boys? Now condition on {BB,BG}\{BB,BG\}: answer 12\tfrac12.

Same family, different information, different answers — see Going Deeper for why the phrasing matters.

Tip

Pitfall. In every trap, how the information was obtained changes the conditioning set. “I met one of the children and he's a boy” is not the same evidence as “at least one child is a boy,” even though both mention a boy. Model the process, not just the sentence.

Try it
Quick check

Monty Hall with 44 doors: you pick a door, the host (who knows where the car is) opens one of the other doors to show a goat, and you switch to one of the two remaining closed doors at random. What is your probability of winning?

Work it on paper before revealing the answer.

Show the answer

Answer: Your first pick is the car with probability 14\tfrac14; then switching always loses. With probability 34\tfrac34 you picked a goat; the host opens another goat door, the car is behind one of the 22 doors you may switch to, and you pick it with probability 12\tfrac12. So

P(win)=34⋅12=38,P(\text{win}) = \tfrac34\cdot\tfrac12 = \boxed{\tfrac38},

better than the 14\tfrac14 from staying.

Going Deeper: Bayesian Updating, Conditioning, and Ambiguity

Concept
Belief as something you update

Bayesian updating treats probability as a state of belief refined by evidence. The posterior after one observation becomes the prior for the next:

P(H∣E1,E2)  ∝  P(E2∣H) P(E1∣H) P(H)⏟posterior after E1.P(H\mid E_1, E_2) \;\propto\; P(E_2\mid H)\,\underbrace{P(E_1\mid H)\,P(H)}_{\text{posterior after }E_1}.

Independent pieces of evidence multiply their likelihood ratios. A rare hypothesis can still win if the evidence is strong enough, and a common one can survive weak evidence — exactly the tension in the medical-test example.

Example
Worked example: updating twice

The rare disease (P(D)=0.001P(D)=0.001) test above comes back positive; a second independent test (same accuracy) is also positive. Now find P(D∣++)P(D\mid ++).

Solution. Use the first posterior P(D∣+)≈0.0902P(D\mid +)\approx 0.0902 as the new prior:

P(D∣++)=(0.99)(0.0902)(0.99)(0.0902)+(0.01)(0.9098)≈0.08930.0893+0.0091≈0.907.P(D\mid ++) = \frac{(0.99)(0.0902)}{(0.99)(0.0902)+(0.01)(0.9098)} \approx \frac{0.0893}{0.0893+0.0091} \approx 0.907.

Two positives push belief from 9%9\% to about 91%91\%. Evidence compounds.

Example
Worked example: why conditioning defies intuition

Why does “at least one boy” give 13\tfrac13 but “the older is a boy” give 12\tfrac12?

Solution. Conditioning removes outcomes unevenly. “Older is a boy” eliminates GGGG and GBGB, leaving two equally likely worlds BB,BGBB,BG. “At least one boy” eliminates only GGGG, leaving three worlds BB,BG,GBBB,BG,GB, and BBBB is just one of them. The information “at least one” is weaker — it does not pin down which child — so it cuts the space less. Intuition fails because we imagine the evidence naming a specific child when it does not.

Example
Worked example: the ambiguity made precise

“A family has two children; I tell you at least one is a boy born on a Tuesday. Both boys?” The Tuesday detail, seemingly irrelevant, shifts the answer to 1327\tfrac{13}{27}, not 13\tfrac13.

Solution sketch. Each child is one of 1414 equally likely (gender, weekday) types. Counting the ordered pairs containing at least one “boy-Tuesday” gives 2727; those with two boys give 1313; hence 1327≈0.481\tfrac{13}{27}\approx 0.481. The lesson: the more specifically the evidence identifies a child, the closer the answer creeps to 12\tfrac12. Ambiguous wording has no single “right” answer until the sampling process is fixed.

Tip

Big picture — conditioning is re-weighting your world. Every result in this unit is one identity, P(A∩B)=P(A∣B)P(B)P(A\cap B)=P(A\mid B)P(B), read in different directions:

  • Forward (trees, multiplication, total probability): split into cases, multiply along paths, add paths to get P(A)P(A).
  • Backward (Bayes): once AA is observed, divide the target path by all paths to get P(Bi∣A)P(B_i\mid A) — prior times likelihood, normalized.
  • Independence is the special case where conditioning changes nothing: P(A∣B)=P(A)P(A\mid B)=P(A).
  • The traps all come from misreading which outcomes the evidence keeps. Always model the process that produced the information, weight by the priors (mind the base rate), and trust the arithmetic over the gut.
Try it
Quick check

A bag has 44 red and 66 blue balls. Two are drawn without replacement. Find the probability that both are red.

Work it on paper before revealing the answer.

Show the answer

Answer: Multiplication rule. There are 44 red among 1010 balls. After a red is removed, 33 red remain among 99:

P(both red)=410⋅39=1290=215.P(\text{both red})=\frac{4}{10}\cdot\frac{3}{9}=\frac{12}{90}=\boxed{\dfrac{2}{15}}.

The Odds Form of Bayes & Sequential Updating

Concept
Bayes as a multiplier on odds

Write Bayes' theorem for two competing hypotheses HH and its complement HcH^c and divide the two versions. The awkward normalizing denominator P(E)P(E) cancels, leaving the odds form:

P(H∣E)P(Hc∣E)⏟posterior odds=P(E∣H)P(E∣Hc)⏟likelihood ratio (LR)⋅P(H)P(Hc)⏟prior odds.\underbrace{\frac{P(H\mid E)}{P(H^c\mid E)}}_{\text{posterior odds}} =\underbrace{\frac{P(E\mid H)}{P(E\mid H^c)}}_{\text{likelihood ratio (LR)}} \cdot\underbrace{\frac{P(H)}{P(H^c)}}_{\text{prior odds}}.

Updating is now pure multiplication: posterior odds == LR ×\times prior odds. For a stream of conditionally independent pieces of evidence E1,…,EnE_1,\dots,E_n the likelihood ratios simply multiply,

P(H∣E1,…,En)P(Hc∣E1,…,En)=(∏k=1nP(Ek∣H)P(Ek∣Hc))P(H)P(Hc).\frac{P(H\mid E_1,\dots,E_n)}{P(H^c\mid E_1,\dots,E_n)} =\left(\prod_{k=1}^{n}\frac{P(E_k\mid H)}{P(E_k\mid H^c)}\right)\frac{P(H)}{P(H^c)}.

This is iterated Bayesian updating: each posterior is the next prior, and in odds language the whole computation collapses to one product. Recover a probability at the end via p=odds1+oddsp=\dfrac{\text{odds}}{1+\text{odds}}.

Example
Worked example: three positive tests, done in odds

A disease has prevalence P(D)=11000P(D)=\tfrac{1}{1000}. A test has sensitivity P(+∣D)=0.99P(+\mid D)=0.99 and false-positive rate P(+∣Dc)=0.01P(+\mid D^c)=0.01, giving likelihood ratio LR=0.990.01=99\mathrm{LR}=\tfrac{0.99}{0.01}=99. Three independent tests all read positive. Find P(D∣+++)P(D\mid {+}{+}{+}).

Solution. Prior odds =1/1000999/1000=1999=\dfrac{1/1000}{999/1000}=\dfrac{1}{999}. Multiply by LR\mathrm{LR} once per positive:

posterior odds=993⋅1999=970299999≈971.3.\text{posterior odds}=99^3\cdot\frac{1}{999}=\frac{970299}{999}\approx 971.3.

Convert back:

P(D∣+++)=971.31+971.3≈0.99897.P(D\mid {+}{+}{+})=\frac{971.3}{1+971.3}\approx 0.99897.

One positive left belief near 9%9\% (the base rate dominated); the odds form shows why each extra positive multiplies the odds by 9999, so three positives overwhelm even a 11-in-10001000 prior.

Example
Worked example: mixed evidence (a positive then a negative)

Same test. A patient tests positive, then negative on an independent retest. What is P(D)P(D) now?

Solution. The negative test has its own likelihood ratio P(−∣D)P(−∣Dc)=0.010.99=199\dfrac{P(-\mid D)}{P(-\mid D^c)}=\dfrac{0.01}{0.99}=\dfrac{1}{99}. Chain both:

posterior odds=99⏟+⋅199⏟−⋅1999⏟prior=1999.\text{posterior odds}=\underbrace{99}_{+}\cdot\underbrace{\tfrac{1}{99}}_{-}\cdot\underbrace{\tfrac{1}{999}}_{\text{prior}}=\frac{1}{999}.

The two tests exactly cancel, returning belief to the prior 11000\tfrac{1}{1000}. Contradictory evidence multiplies to a net ratio of 11 — a fact almost invisible in the fraction form but obvious in odds.

Tip

Tip. Whenever a problem chains several independent clues toward one yes/no hypothesis, switch to odds: multiply the prior odds by each likelihood ratio, then convert once at the end. It sidesteps the denominator entirely and makes “how much does this clue matter?” literally a multiplier.

Try it
Quick check

A hypothesis has prior odds 1:41:4. A piece of evidence is 66 times as likely if the hypothesis is true as if it is false. Find the posterior probability of the hypothesis.

Work it on paper before revealing the answer.

Show the answer

Answer: Posterior odds == likelihood ratio ×\times prior odds =6⋅14=32= 6\cdot\tfrac14 = \tfrac32, i.e. 3:23:2. Converting, p=3/21+3/2=35p = \tfrac{3/2}{1 + 3/2} = \boxed{\tfrac35}.

Markov Chains & Transition Matrices

Concept
Memoryless step-by-step randomness

A Markov chain moves among states 1,…,m1,\dots,m so that the next state depends only on the current one, not the past history:

P(Xn+1=j∣Xn=i, Xn−1,… )=P(Xn+1=j∣Xn=i)=:pij.P(X_{n+1}=j\mid X_n=i,\ X_{n-1},\dots)=P(X_{n+1}=j\mid X_n=i)=:p_{ij}.

Collect these into the transition matrix P=[pij]P=[p_{ij}]; each row sums to 11. If the current distribution over states is a row vector v\mathbf{v}, then after one step it is vP\mathbf{v}P, and after nn steps vPn\mathbf{v}P^{n}. The (i,j)(i,j) entry of PnP^{n} is exactly P(Xn=j∣X0=i)P(X_n=j\mid X_0=i) — multi-step probabilities are just matrix powers.

A stationary distribution π\boldsymbol{\pi} satisfies πP=π\boldsymbol{\pi}P=\boldsymbol{\pi} with ∑iπi=1\sum_i\pi_i=1: the chain, once in π\boldsymbol{\pi}, stays distributed as π\boldsymbol{\pi} forever. An absorbing state has pii=1p_{ii}=1 (once entered, never left).

Example
Worked example: sunny/rainy two-step and long-run
SunnyRainy0.20.40.80.6
Each arrow is one entry of PP; the arrows leaving a state carry probabilities that add to 11.

Weather follows a chain on states (Sunny, Rainy) with

P=[0.80.20.40.6].P=\begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix}.

(a) If today is sunny, probability it is rainy the day after tomorrow? (b) What fraction of days are sunny in the long run?

Solution. (a) Compute the two-step matrix:

P2=[0.80.20.40.6][0.80.20.40.6]=[0.720.280.560.44].P^2=\begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix} \begin{bmatrix} 0.8 & 0.2 \\ 0.4 & 0.6 \end{bmatrix} =\begin{bmatrix} 0.72 & 0.28 \\ 0.56 & 0.44 \end{bmatrix}.

The (Sunny →\to Rainy) entry is 0.280.28.

(b) Solve πP=π\boldsymbol{\pi}P=\boldsymbol{\pi} with π=(πS,πR)\boldsymbol{\pi}=(\pi_S,\pi_R), πS+πR=1\pi_S+\pi_R=1. The first component gives 0.8πS+0.4πR=πS0.8\pi_S+0.4\pi_R=\pi_S, i.e. 0.4πR=0.2πS0.4\pi_R=0.2\pi_S, so πS=2πR\pi_S=2\pi_R. With πS+πR=1\pi_S+\pi_R=1 we get πS=23, πR=13\pi_S=\tfrac23,\ \pi_R=\tfrac13. Sunny two-thirds of the time.

Example
Worked example: a three-state absorbing chain

A token sits on states A,B,CA,B,C with CC absorbing:

P=[0121212012001].P=\begin{bmatrix} 0 & \tfrac12 & \tfrac12 \\[2pt] \tfrac12 & 0 & \tfrac12 \\[2pt] 0 & 0 & 1 \end{bmatrix}.

Starting at AA, (a) what is the probability that the token has not been absorbed after nn steps, and (b) what is the expected number of steps until absorption?

Solution. (a) From AA and from BB alike, each step moves to CC with probability 12\tfrac12 and otherwise to the other unabsorbed state. So the token survives each step with probability 12\tfrac12, independently of the past, and P(not absorbed after n steps)=(12)nP(\text{not absorbed after } n \text{ steps}) = \left(\tfrac12\right)^n. This tends to 00, so absorption is certain: the powers PnP^n push all the mass into column CC.

(b) Let eA,eBe_A, e_B be the expected steps to absorption. Conditioning on the first step, eA=1+12eBe_A = 1 + \tfrac12 e_B and eB=1+12eAe_B = 1 + \tfrac12 e_A. By symmetry eA=eBe_A = e_B, so eA=1+12eAe_A = 1 + \tfrac12 e_A and eA=2e_A = 2 steps, the mean of a geometric wait with p=12p = \tfrac12.

Tip

Tip. Rows of PP must each sum to 11 — always sanity-check this first. Multi-step questions (nn days later, nn moves later) are PnP^n; “in the long run / eventually / steady state” questions are the stationary equation πP=π\boldsymbol{\pi}P=\boldsymbol{\pi}. Never confuse a single large power with the stationary vector unless the chain has actually settled.

Gambler's Ruin

Concept
Reaching NN before 00

A gambler holding $k\$k bets $1\$1 per round, winning with probability pp and losing with probability q=1−pq=1-p, until reaching a target $N\$N (win) or $0\$0 (ruin). Let rkr_k be the probability of reaching NN before 00 starting from kk. Conditioning on the first bet (this is first-step analysis) gives the recurrence

rk=p rk+1+q rk−1,r0=0, rN=1.r_k=p\,r_{k+1}+q\,r_{k-1},\qquad r_0=0,\ r_N=1.

Solving this linear recurrence yields the classic formulas

rk={kN,p=q=12 (fair game),1−(q/p)k1−(q/p)N,p≠q (biased game).r_k=\begin{cases}\dfrac{k}{N}, & p=q=\tfrac12 \ \text{(fair game)},\\[10pt] \dfrac{1-(q/p)^k}{1-(q/p)^N}, & p\neq q\ \text{(biased game)}.\end{cases}

The fair case is a straight line in kk; the biased case is governed by the ratio q/pq/p.

Example
Worked example: fair game, doubling your money

You start with $50\$50 and play a fair game (p=12p=\tfrac12), quitting at $0\$0 or $100\$100. Probability you reach $100\$100?

Solution. With k=50k=50, N=100N=100, p=q=12p=q=\tfrac12:

r50=kN=50100=12.r_{50}=\frac{k}{N}=\frac{50}{100}=\frac12.

In a fair game the chance of hitting the target before ruin is just your current fortune as a fraction of the target — no arithmetic beyond a ratio.

Example
Worked example: a slightly unfair game

A gambler starts at $1\$1, wants to reach $5\$5, and wins each $1\$1 bet with probability p=0.4p=0.4 (so q=0.6q=0.6, ratio q/p=32q/p=\tfrac32). Probability of success?

Solution. Use the biased formula with k=1, N=5, q/p=32k=1,\ N=5,\ q/p=\tfrac32:

r1=1−(3/2)11−(3/2)5=1−1.51−7.59375=−0.5−6.59375≈0.0758.r_1=\frac{1-(3/2)^1}{1-(3/2)^5}=\frac{1-1.5}{1-7.59375}=\frac{-0.5}{-6.59375}\approx 0.0758.

Only about 7.6%7.6\%. A small per-bet disadvantage compounds brutally over the distance to the target: fighting the house edge across many rounds is nearly hopeless. (Contrast the fair game, where the same k/N=15=20%k/N=\tfrac15=20\%.)

Tip

Big picture. Gambler's ruin is the template for every “random walk with two barriers” problem: set rkr_k for the boundary event, condition on the first step to get rk=p rk+1+q rk−1r_k=p\,r_{k+1}+q\,r_{k-1}, and impose the boundary values. The same recurrence machinery reappears in fair-coin streak problems, tennis deuce, and best-of-NN series.

First-Step Analysis & Conditional Expectation (Unit 9 Preview)

Concept
Condition on the first move to set up equations

First-step analysis solves “how long / how likely” questions on a chain by conditioning on the very first transition and using the memoryless property: after one step the problem looks like the same problem from the new state. This turns a hard infinite process into a small linear system.

For expected times it uses the tower property of conditional expectation,

E[T]=∑iE[T∣first step to i] P(first step to i),E[T]=\sum_i E[T\mid \text{first step to }i]\,P(\text{first step to }i),

where reaching a new state ii contributes the 11 step already taken plus the expected remaining time Ei[T]E_i[T] from ii. Letting ek=E[steps to absorption from k]e_k=E[\text{steps to absorption from }k] typically yields a recurrence such as ek=1+p ek+1+q ek−1e_k=1+p\,e_{k+1}+q\,e_{k-1} with e=0e=0 at absorbing states. This conditional-expectation viewpoint is the gateway to Unit 9.

Example
Worked example: expected flips to get two heads in a row

Let ee be the expected number of fair-coin flips to first see HH. Track states by current progress: S0S_0 (no useful streak), S1S_1 (one HH so far). Let a=E[flips from S0]a=E[\text{flips from }S_0], b=E[flips from S1]b=E[\text{flips from }S_1].

Solution. First-step analysis on each state:

a=1+12 b+12 a,b=1+12⋅0+12 a.a=1+\tfrac12\,b+\tfrac12\,a,\qquad b=1+\tfrac12\cdot 0+\tfrac12\,a.

From the first equation 12a=1+12b⇒a=2+b\tfrac12 a=1+\tfrac12 b\Rightarrow a=2+b. Substitute into the second: b=1+12a=1+12(2+b)=2+12bb=1+\tfrac12 a=1+\tfrac12(2+b)=2+\tfrac12 b, so 12b=2⇒b=4\tfrac12 b=2\Rightarrow b=4, and a=6a=6. The expected number of flips is 6\boxed{6}. (The general pattern for a streak of nn heads is 2n+1−22^{n+1}-2.)

Example
Worked example: expected duration of a fair gambler's game

In the fair gambler's-ruin game (p=12p=\tfrac12), let eke_k be the expected number of bets until hitting 00 or NN from $k\$k. Find a formula.

Solution. Condition on the first bet:

ek=1+12 ek+1+12 ek−1,e0=eN=0.e_k=1+\tfrac12\,e_{k+1}+\tfrac12\,e_{k-1},\qquad e_0=e_N=0.

Rewrite as ek+1−2ek+ek−1=−2e_{k+1}-2e_k+e_{k-1}=-2: the second difference is constant, so eke_k is quadratic. Trying ek=k(N−k)e_k=k(N-k) gives (k+1)(N−k−1)−2k(N−k)+(k−1)(N−k+1)=−2(k+1)(N-k-1)-2k(N-k)+(k-1)(N-k+1)=-2, which checks, and e0=eN=0e_0=e_N=0. Hence

ek=k(N−k).e_k=k(N-k).

Starting at the midpoint k=N/2k=N/2 the game lasts an expected N2/4N^2/4 bets — surprisingly long. First-step analysis converts the recurrence directly into the answer.

Tip

Bridge to Unit 9. Everything here is one idea: condition on the first step, then reuse the structure of the problem. For probabilities it gives rk=p rk+1+q rk−1r_k=p\,r_{k+1}+q\,r_{k-1}; for expected times it gives ek=1+p ek+1+q ek−1e_k=1+p\,e_{k+1}+q\,e_{k-1}. The tool is conditional expectation and its tower property, E[X]=E[E[X∣Y]]E[X]=E\big[E[X\mid Y]\big] — the central engine of Unit 9. Master first-step analysis now and expectation will feel like the same move applied to averages instead of probabilities.

Why It Works

Bayes' theorem is two ways of writing the same overlap: P(A∩B)=P(A∣B)P(B)=P(B∣A)P(A)P(A\cap B) = P(A\mid B)P(B) = P(B\mid A)P(A), so P(A∣B)=P(B∣A)P(A)P(B)P(A\mid B) = \tfrac{P(B\mid A)P(A)}{P(B)}. The denominator expands by cases (the law of total probability), which is where the base rate enters. A tree diagram makes this automatic: the probability of a path is the product along it, and conditioning on an outcome keeps only the paths ending there and renormalizes.

Tip
Reading a proof

Do not read a proof the way you read a rule. Cover the last line, ask what the previous line forces, and only then uncover it. If a step feels like magic, that is the step to work by hand with a concrete number.

Formulas, Proofs & Tips

Tip
Conditional probability and Bayes’ theorem
P(A∣B)=P(A∩B)P(B),P(A∣B)=P(B∣A)P(A)P(B)P(A\mid B)=\frac{P(A\cap B)}{P(B)},\qquad P(A\mid B)=\frac{P(B\mid A)P(A)}{P(B)}

What it means. Knowing BB happened shrinks the sample space to BB. Bayes reverses the conditioning.

Example. If P(A∩B)=0.1P(A\cap B)=0.1 and P(B)=0.5P(B)=0.5, then P(A∣B)=0.10.5=0.2P(A\mid B)=\tfrac{0.1}{0.5}=0.2.

Why it works. Once BB is known, only outcomes inside BB remain possible, so probabilities are rescaled by dividing by P(B)P(B). Bayes follows because P(A∩B)P(A\cap B) can be written two ways: P(A∣B)P(B)=P(B∣A)P(A)P(A\mid B)P(B)=P(B\mid A)P(A).

Tip. AA and BB are independent exactly when P(A∣B)=P(A)P(A\mid B)=P(A), i.e. P(A∩B)=P(A)P(B)P(A\cap B)=P(A)P(B).