Math ClubMath Club
v1 · padrão canônico

Lesson 79 — Deep Dive into Bayes' Theorem

Priors, posteriors, and sequential updating. Odds form, Beta-binomial conjugate prior, base rate fallacy, Naive Bayes. Applications in medical diagnosis, spam filtering, and ML.

Used in: Stochastik LK alemão · H2 Math Statistics singapurense · Math B japonês · Equiv. AP Statistics EUA

P(HE)=P(EH)P(H)P(E)P(H \mid E) = \frac{P(E \mid H)\,P(H)}{P(E)}

Bayes' theorem is the rule for rational belief updating. The prior P(H)P(H) represents what we believe before seeing the evidence; the likelihood P(EH)P(E \mid H) measures how much the evidence favors the hypothesis; the posterior P(HE)P(H \mid E) is the updated belief after observing EE. The denominator P(E)P(E) normalizes the result so that the probability sums to 1.

Choose your door

Rigorous notation, full derivation, hypotheses

Definitions and theorems

Conditional probability

"The conditional probability P(EF)P(E \mid F), the probability of EE given FF, expresses the probability of EE when we know that FF has occurred. It can be computed using the formula P(EF)=P(EF)/P(F)P(E \mid F) = P(EF)/P(F), assuming P(F)>0P(F) > 0." — Grinstead & Snell, Introduction to Probability, §4.1

Law of total probability

Bayes' theorem

"Bayes' Theorem is just a formula that comes from the definition of conditional probability. Yet it is extremely powerful, and is the key to understanding what it means to rationally revise your beliefs in light of new evidence." — OpenIntro Statistics 4e, §3.2

Odds form

Sequential updating

Beta-binomial conjugate prior

SVG — Bayes diagram in 2×2 table

2×2 Table — Positive Predictive ValueSick (prevalence p)Test + : sens · p(true positive)TPHealthy (1 − p)Test + : (1−spec)·(1−p)(false positive)FPPPV = TP / (TP + FP)= posterior P(sick | test+)Low prevalence → FP dominates → Low PPV (base rate fallacy)

Absolute frequency diagram. The PPV (Positive Predictive Value) is the Bayesian posterior P(sick | positive test). When prevalence is low, false positives outweigh true positives even with a high-quality test.

Solved examples

Exercise list

40 exercises · 10 with worked solution (25%)

Application 18Understanding 4Modeling 10Challenge 5Proof 3
  1. Ex. 79.1ApplicationAnswer key

    P(A)=0.3P(A) = 0.3, P(B)=0.5P(B) = 0.5, P(AB)=0.15P(A \cap B) = 0.15. Calculate P(AB)P(A \mid B).

    Show solution
    By definition: P(AB)=P(AB)/P(B)=0.15/0.50=0.30P(A \mid B) = P(A \cap B)/P(B) = 0.15/0.50 = 0.30. Note that P(AB)=P(A)=0.3P(A \mid B) = P(A) = 0.3, so AA and BB are independent.
  2. Ex. 79.2Application

    P(AB)=0.6P(A \mid B) = 0.6, P(B)=0.5P(B) = 0.5. Calculate P(AB)P(A \cap B).

    Show solution
    By the product rule: P(AB)=P(AB)P(B)=0.60×0.50=0.30P(A \cap B) = P(A \mid B) \cdot P(B) = 0.60 \times 0.50 = 0.30.
  3. Ex. 79.3Application

    P(A)=0.1P(A) = 0.1, P(BA)=0.8P(B \mid A) = 0.8, P(BAˉ)=0.2P(B \mid \bar A) = 0.2. Calculate P(B)P(B).

    Show solution
    Law of total probability: P(B)=P(BA)P(A)+P(BAˉ)P(Aˉ)=0.8×0.1+0.2×0.9=0.08+0.18=0.26P(B) = P(B \mid A)P(A) + P(B \mid \bar A)P(\bar A) = 0.8 \times 0.1 + 0.2 \times 0.9 = 0.08 + 0.18 = 0.26.
    Show step-by-step (with the why)
    1. Identify the two hypotheses: AA (with probability 0.1) and Aˉ\bar A (with probability 0.9).
    2. Note the likelihoods: P(BA)=0.8P(B \mid A) = 0.8 and P(BAˉ)=0.2P(B \mid \bar A) = 0.2.
    3. Apply the law of total probability — weighted sum of likelihoods by priors: P(B)=0.8×0.1+0.2×0.9=0.26P(B) = 0.8 \times 0.1 + 0.2 \times 0.9 = 0.26.
    4. Tip: the law of total probability is the denominator of Bayes. Calculate it before applying the theorem.
  4. Ex. 79.4Application

    With the data from exercise 79.3, calculate P(AB)P(A \mid B).

    Show solution
    Using the data from the previous exercise and Bayes: P(AB)=P(BA)P(A)/P(B)=0.8×0.1/0.26=0.08/0.260.308P(A \mid B) = P(B \mid A)P(A)/P(B) = 0.8 \times 0.1 / 0.26 = 0.08/0.26 \approx 0.308.
  5. Ex. 79.5ApplicationAnswer key

    Disease with 0.5% prevalence. Diagnostic test: 95% sensitivity, 95% specificity. Calculate the PPV using frequencies in 10,000 people.

    Show solution
    In 10,000 people: sick = 50, TP = 50×0.95=47.550 \times 0.95 = 47.5, FP = 9950×0.05=497.59950 \times 0.05 = 497.5. PPV = 47.5/(47.5+497.5)8.7%47.5/(47.5 + 497.5) \approx 8.7\%. Despite the high quality of the test, the PPV is low because the prevalence is very low.
  6. Ex. 79.6ApplicationAnswer key

    Same data as exercise 79.5, but with 50% prevalence. Calculate the PPV and compare with the previous result.

    Show solution
    With 50% prevalence: in 10,000, sick = 5,000, TP = 4,750, FP = 250. PPV = 4750/5000=0.954750/5000 = 0.95, or 95%. Compare with 8.7% from exercise 79.5: the same test has a radically different PPV depending on prevalence.
  7. Ex. 79.7Application

    Spam filter: P(spam)=0.3P(\text{spam}) = 0.3. Word "FREE" appears in 60% of spams and 5% of legitimate emails. Calculate P(spamFREE)P(\text{spam} \mid \text{FREE}).

    Show solution
    Prior odds of spam: 0.30/0.700.30/0.70. Likelihood ratio: P(Gspam)/P(Gham)=0.60/0.05=12P(G|\text{spam})/P(G|\text{ham}) = 0.60/0.05 = 12. Posterior odds: (0.30/0.70)×12=3.6/0.705.14(0.30/0.70) \times 12 = 3.6/0.70 \approx 5.14. Posterior: 5.14/6.1483.7%5.14/6.14 \approx 83.7\%.
    Show step-by-step (with the why)
    1. Prior: P(spam)=0.30P(\text{spam}) = 0.30, P(ham)=0.70P(\text{ham}) = 0.70.
    2. Likelihoods: P(FREEspam)=0.60P(\text{FREE} \mid \text{spam}) = 0.60, P(FREEham)=0.05P(\text{FREE} \mid \text{ham}) = 0.05.
    3. Numerator of Bayes: 0.60×0.30=0.180.60 \times 0.30 = 0.18.
    4. Denominator: 0.18+0.05×0.70=0.18+0.035=0.2150.18 + 0.05 \times 0.70 = 0.18 + 0.035 = 0.215.
    5. Posterior: 0.18/0.2150.8370.18/0.215 \approx 0.837.
    6. Mental shortcut: LR = 12 transforms prior odds of 3:73:7 into posterior odds of 36:75.14:136:7 \approx 5.14:1, i.e., approximately 84% spam.
  8. Ex. 79.8Application

    Urn A: 2 red, 3 blue. Urn B: 5 red, 1 blue. An urn is chosen at random and a red ball is drawn. What is the probability the urn is A?

    Show solution
    Prior: P(A)=P(B)=0.5P(A) = P(B) = 0.5. Likelihoods: P(RA)=2/5=0.4P(R \mid A) = 2/5 = 0.4, P(RB)=5/60.833P(R \mid B) = 5/6 \approx 0.833. Total: P(R)=0.4×0.5+0.833×0.5=0.617P(R) = 0.4 \times 0.5 + 0.833 \times 0.5 = 0.617. Posterior: P(AR)=0.2/0.6170.324P(A \mid R) = 0.2/0.617 \approx 0.324.
  9. Ex. 79.9ApplicationAnswer key

    3 coins: 2 fair, 1 double-headed. One is chosen at random, flipped once, comes up heads. What is the probability the chosen coin is the double-headed one?

    Show solution
    3 coins: 2 fair (prob head = 1/2) and 1 double-headed (prob head = 1). Prior: P(2-headed)=1/3P(\text{2-headed}) = 1/3, P(fair)=2/3P(\text{fair}) = 2/3. Likelihood of head: P(H2h)=1P(H \mid 2h) = 1, P(Hfair)=1/2P(H \mid \text{fair}) = 1/2. Total: P(H)=1×1/3+1/2×2/3=2/3P(H) = 1 \times 1/3 + 1/2 \times 2/3 = 2/3. Posterior: P(2hH)=(1×1/3)/(2/3)=1/2P(2h \mid H) = (1 \times 1/3)/(2/3) = 1/2.
  10. Ex. 79.10Application

    P(smoker)=0.2P(\text{smoker}) = 0.2. P(cancersmoker)=0.1P(\text{cancer} \mid \text{smoker}) = 0.1. P(cancer¬smoker)=0.01P(\text{cancer} \mid \neg\text{smoker}) = 0.01. Given a person has cancer, what is the probability they are a smoker?

    Show solution
    Prior: P(S)=0.2P(S) = 0.2. Likelihoods: P(CS)=0.1P(C \mid S) = 0.1, P(C¬S)=0.01P(C \mid \neg S) = 0.01. Total: P(C)=0.1×0.2+0.01×0.8=0.02+0.008=0.028P(C) = 0.1 \times 0.2 + 0.01 \times 0.8 = 0.02 + 0.008 = 0.028. Posterior: P(SC)=0.02/0.02871.4%P(S \mid C) = 0.02/0.028 \approx 71.4\%.
  11. Ex. 79.11Application

    Sequential updating: two positive tests with 90% sensitivity and 90% specificity, applied to a disease with 1% prevalence. Use the posterior of the 1st test as the prior of the 2nd. What is the PPV after both consecutive positive results?

    Show solution
    Step 1 (1st positive test, 90% sens, 90% spec, 1% prevalence): PPV1=(0.9×0.01)/(0.9×0.01+0.1×0.99)=0.009/0.1088.33%\text{PPV}_1 = (0.9 \times 0.01)/(0.9 \times 0.01 + 0.1 \times 0.99) = 0.009/0.108 \approx 8.33\%. Step 2 (2nd positive test, same test, prior = 8.33%): PPV2=(0.9×0.0833)/(0.9×0.0833+0.1×0.9167)=0.075/0.16744.9%\text{PPV}_2 = (0.9 \times 0.0833)/(0.9 \times 0.0833 + 0.1 \times 0.9167) = 0.075/0.167 \approx 44.9\%. After two independent positive tests, the probability rises from 1% to almost 45%.
    Show step-by-step (with the why)
    1. Calculate PPV after the 1st positive test with 1% prevalence, sens = spec = 90%: PPV1=0.009/0.1088.33%\text{PPV}_1 = 0.009/0.108 \approx 8.33\%.
    2. Use 8.33% as the new prior for the 2nd test.
    3. Calculate PPV2_2: numerator = 0.9×0.0833=0.0750.9 \times 0.0833 = 0.075; denominator = 0.075+0.1×0.9167=0.1670.075 + 0.1 \times 0.9167 = 0.167.
    4. PPV244.9%\text{PPV}_2 \approx 44.9\%. With each positive test, the probability grows — but slowly when the prior is very low.
    5. Curiosity: via odds form, LR+=9\text{LR}^+ = 9 for each test. After two tests: prior odds =0.01/0.990.0101= 0.01/0.99 \approx 0.0101; posterior odds =0.0101×9×9=0.818= 0.0101 \times 9 \times 9 = 0.818; posterior =0.818/1.81845%= 0.818/1.818 \approx 45\%. Same result, faster.
  12. Ex. 79.12Application

    For a test with 90% sensitivity and 95% specificity, calculate the positive likelihood ratio LR+=sens/(1spec)\text{LR}^+ = \text{sens}/(1 - \text{spec}).

    Show solution
    LR+=sens/(1spec)=0.90/(10.95)=0.90/0.05=18\text{LR}^+ = \text{sens}/(1 - \text{spec}) = 0.90/(1 - 0.95) = 0.90/0.05 = 18. Interpretation: a positive result makes the disease 18 times more likely (in odds scale) than before the test.
  13. Ex. 79.13Application

    Prior odds of 1:99 (1% prevalence). LR+=18\text{LR}^+ = 18 (90% sensitivity, 95% specificity). Calculate the posterior odds and the posterior.

    Show solution
    Prior odds: 1/991/99. LR+=0.9/0.05=18\text{LR}^+ = 0.9/0.05 = 18. Posterior odds: (1/99)×18=18/990.182(1/99) \times 18 = 18/99 \approx 0.182. Posterior: 0.182/1.18215.4%0.182/1.182 \approx 15.4\%.
  14. Ex. 79.14Application

    Which of the following values is the correct posterior in a context with prior odds 1:99 and LR+=18\text{LR}^+ = 18?

    Select the correct option
    Select an option first
    Show solution
    The correct alternative is 15.4%. The prior odds is 1:99, the LR+\text{LR}^+ = 18, so posterior odds = 18/99 and posterior = 18/117 ≈ 15.4%. The other alternatives map classic errors: confusing PPV with sensitivity (90%), ignoring the test (keeping 1%), or forgetting the prior (50% incorrect).
  15. Ex. 79.15Application

    Prior θBeta(2,2)\theta \sim \text{Beta}(2, 2). 7 heads observed in 10 flips. Determine the posterior.

    Show solution
    Prior Beta(2, 2). Flips: n=10n = 10, k=7k = 7 heads. Posterior: Beta(2+7,  2+107)=Beta(9,5)\text{Beta}(2 + 7,\; 2 + 10 - 7) = \text{Beta}(9, 5). Posterior mean: 9/140.6439/14 \approx 0.643.
  16. Ex. 79.16Application

    Prior θBeta(1,1)\theta \sim \text{Beta}(1, 1) (uniform). 0 heads observed in 5 flips. Determine the posterior and its mean.

    Show solution
    Posterior: Beta(1+0,  1+50)=Beta(1,6)\text{Beta}(1 + 0,\; 1 + 5 - 0) = \text{Beta}(1, 6). Posterior mean: 1/70.1431/7 \approx 0.143. Even without any heads, the posterior does not go to zero because the uniform prior assigned some positive mass to all values of θ\theta.
  17. Ex. 79.17Application

    In exercise 79.15, what is the posterior mean?

    Show solution
    From exercise 79.15: posterior Beta(9, 5). Mean: α/(α+β)=9/140.643\alpha/(\alpha + \beta) = 9/14 \approx 0.643.
  18. Ex. 79.18Application

    Prior θBeta(2,8)\theta \sim \text{Beta}(2, 8). New batch: 30 parts inspected, 6 defective. Determine the posterior and posterior mean.

    Show solution
    Prior Beta(2, 8), n = 30, k = 6. Posterior: Beta(2+6,8+24)=Beta(8,32)\text{Beta}(2 + 6, 8 + 24) = \text{Beta}(8, 32). Posterior mean: 8/40=0.208/40 = 0.20. Compare with MLE = 6/30=0.206/30 = 0.20: they coincide because the prior was already calibrated to the same proportion.
  19. Ex. 79.19ModelingAnswer key

    COVID-19 in endemic phase: 5% prevalence. Rapid test: 80% sensitivity, 95% specificity. Calculate the PPV using frequencies in 10,000 people. Is it worth automatically isolating all positives?

    Show solution
    COVID screening: 5% prevalence, 80% sens, 95% spec. In 10,000 people: sick = 500, TP = 400, healthy = 9,500, FP = 475. PPV = 400/875 ≈ 45.7%. Less than half of the positives are truly infected — justifies confirmation with PCR before prolonged isolation decisions.
    Show step-by-step (with the why)
    1. Calculate the number of sick people in the population of 10,000: 10000×0.05=50010000 \times 0.05 = 500.
    2. TP = sick × sensitivity = 500×0.80=400500 \times 0.80 = 400.
    3. FP = healthy × (1 − specificity) = 9500×0.05=4759500 \times 0.05 = 475.
    4. PPV = TP / (TP + FP) = 400/87545.7%400/875 \approx 45.7\%.
    5. Observation: with lower sensitivity (80% vs 95%), the PPV falls even more than in the introductory example. Prevalence and specificity are the determining factors of PPV for population screening.
  20. Ex. 79.20Modeling

    Naive Bayes for email: P(spam)=0.3P(\text{spam}) = 0.3. In training: "FREE" appears in 60% of spams and 5% of hams; "won" appears in 50% of spams and 10% of hams. An email contains both words. Classify assuming conditional independence.

    Show solution
    Classify: prior odds spam 3:7. LR for "FREE": 0.6/0.05=120.6/0.05 = 12. LR for "won": P(wonspam)=0.5P(\text{won}|\text{spam}) = 0.5, P(wonham)=0.1P(\text{won}|\text{ham}) = 0.1, LR = 5. Posterior odds = 3/7×12×5=180/725.73/7 \times 12 \times 5 = 180/7 \approx 25.7. Posterior = 25.7/26.796.3%25.7/26.7 \approx 96.3\%. Classifies as spam.
  21. Ex. 79.21Modeling

    Three diseases: A (10% in population), B (5%), C (1%). Patient presents symptom S with P(SA)=0.3P(S|A) = 0.3, P(SB)=0.9P(S|B) = 0.9, P(SC)=0.9P(S|C) = 0.9. Which disease is most likely?

    Show solution
    Priors: P(A)=0.10P(A) = 0.10, P(B)=0.05P(B) = 0.05, P(C)=0.01P(C) = 0.01. Likelihoods: P(SA)=0.3P(S|A) = 0.3, P(SB)=0.9P(S|B) = 0.9, P(SC)=0.9P(S|C) = 0.9. Unnormalized posteriors: A: 0.03; B: 0.045; C: 0.009. Normalize: sum = 0.084. P(AS)35.7%P(A|S) \approx 35.7\%, P(BS)53.6%P(B|S) \approx 53.6\%, P(CS)10.7%P(C|S) \approx 10.7\%. Most likely diagnosis: disease B.
  22. Ex. 79.22Modeling

    Prosecutor's fallacy: DNA evidence has a frequency of 1/1000 in the population. The prosecutor claims the probability of innocence is 1/1000. Why is this reasoning wrong? Calculate the correct posterior assuming there are 100,000 plausible suspects in the city.

    Show solution
    See the referenced source for the detailed solution.
  23. Ex. 79.23ModelingAnswer key

    Fraud classifier: 95% sensitivity, 99.9% specificity. Frauds: 0.1% of transactions. Calculate the PPV. How many false positives for every true positive?

    Show solution
    Fraud: 0.1% prevalence, 95% sens, 99.9% spec. In 1,000,000 transactions: frauds = 1,000, TP = 950, FP = 999000×0.001=999999000 \times 0.001 = 999. PPV = 950/(950+999)48.7%950/(950 + 999) \approx 48.7\%. For every genuine alert, there is almost 1 false positive. In practice: automatic screening, but human review before blocking definitively.
  24. Ex. 79.24Modeling

    Pregnancy test: 99% sensitivity, 98% specificity. Woman with prior probability of pregnancy of 30%. Calculate the PPV.

    Show solution
    Prev 30%, sens 99%, spec 98%. PPV = (0.99×0.30)/(0.99×0.30+0.02×0.70)=0.297/0.31195.5%(0.99 \times 0.30)/(0.99 \times 0.30 + 0.02 \times 0.70) = 0.297/0.311 \approx 95.5\%. With a prior of 30%, the PPV is already very high — the high prevalence compensates for the small false positive rate.
  25. Ex. 79.25ModelingAnswer key

    Polygraph: 70% sensitivity, 80% specificity. In interrogation with a suspect who has a 5% prior of guilt. Calculate the posterior after a positive result. Is the result admissible as sufficient evidence to convict?

    Show solution
    Prior odds: 0.05/0.950.05260.05/0.95 \approx 0.0526. Polygraph: 70% sens, 80% spec. LR+=0.70/0.20=3.5\text{LR}^+ = 0.70/0.20 = 3.5. Posterior odds: 0.0526×3.50.1840.0526 \times 3.5 \approx 0.184. Posterior: 0.184/1.18415.5%0.184/1.184 \approx 15.5\%. With only 15% posterior probability of guilt, it is not reliable as sufficient evidence for conviction.
  26. Ex. 79.26ModelingAnswer key

    Two independent positive tests (sens1_1 = 0.9, spec1_1 = 0.95; sens2_2 = 0.85, spec2_2 = 0.90). Prevalence 2%. Calculate the posterior after both positive results via sequential updating.

    Show solution
    Two independent positive tests: sensitivities 0.9 and 0.85; specificities 0.95 and 0.90; prevalence 2%. After T1+: P1=(0.9×0.02)/(0.9×0.02+0.05×0.98)=0.018/0.0670.269P_1 = (0.9 \times 0.02)/(0.9 \times 0.02 + 0.05 \times 0.98) = 0.018/0.067 \approx 0.269. After T2+ with prior 0.269: P2=(0.85×0.269)/(0.85×0.269+0.10×0.731)=0.229/0.3020.758P_2 = (0.85 \times 0.269)/(0.85 \times 0.269 + 0.10 \times 0.731) = 0.229/0.302 \approx 0.758.
  27. Ex. 79.27Modeling

    In a lineup, one suspect has red hair (H) with a 70% probability of being the culprit. A witness identifies the red-haired one with 90% probability when the culprit is H, and erroneously 15% of the time when the culprit is not H. Given the witness pointed to H, what is the posterior of guilt?

    Show solution
    P(H)=0.70P(\text{H}) = 0.70, P(C)=0.30P(\text{C}) = 0.30. Witness identifies suspect H with probability 0.9 when it is H, and errs 0.15 of the time when it is C. P(id H)=0.9×0.70+0.15×0.30=0.63+0.045=0.675P(\text{id H}) = 0.9 \times 0.70 + 0.15 \times 0.30 = 0.63 + 0.045 = 0.675. P(Hid H)=0.63/0.67593.3%P(H \mid \text{id H}) = 0.63/0.675 \approx 93.3\%.
  28. Ex. 79.28Modeling

    Quality control with 3 lines (A: 40% of production, 2% defect; B: 35%, 3%; C: 25%, 5%). A defective part is found. Determine the probability of each line being the origin.

    Show solution
    Line A: 40%, 2% defect. Line B: 35%, 3% defect. Line C: 25%, 5% defect. Upon finding a defective part: posterior proportional to defect rate × line proportion. P(AD)0.02×0.40=0.008P(A \mid D) \propto 0.02 \times 0.40 = 0.008; P(BD)0.03×0.35=0.0105P(B \mid D) \propto 0.03 \times 0.35 = 0.0105; P(CD)0.05×0.25=0.0125P(C \mid D) \propto 0.05 \times 0.25 = 0.0125. Total = 0.031. Posteriors: A ≈ 25.8%, B ≈ 33.9%, C ≈ 40.3%. Line C is the most likely source of the defective part.
  29. Ex. 79.29Understanding

    What is the base rate fallacy?

    Select the correct option
    Select an option first
    Show solution
    The base rate fallacy is specifically the failure to incorporate prevalence (prior) when calculating the posterior probability. The other options describe other types of errors, but not the base rate fallacy.
  30. Ex. 79.30Understanding

    Why does the prior matter even in "objective science"? An analysis that ignores the prior is equivalent to what implicit assumption?

    Show solution
    The prior matters because it is the starting point of Bayesian updating. Without a prior, there is no numerator in Bayes — the formula does not produce a posterior. In practice, even "objective" analyses imply priors: testing H0H_0 with a pp-value is equivalent to assigning a point prior at θ=θ0\theta = \theta_0 and rejecting if the evidence is unlikely under that prior. Saying that a prior is "subjective" while the pp-value is "objective" is an illusion — the objectivity of the pp-value lies in the error control procedures, not in the absence of assumptions about the parameters.
  31. Ex. 79.31Understanding

    Two independent positive tests with likelihood ratios r1r_1 and r2r_2. What is the effect on the odds form?

    Select the correct option
    Select an option first
    Show solution
    When tests are conditionally independent given the hypothesis, the combined likelihood ratio is the product of the individual ratios: LRtotal+=r1×r2\text{LR}^+_{\text{total}} = r_1 \times r_2. In odds form: posterior odds = prior odds ×r1×r2\times r_1 \times r_2. Adding would be incorrect — ratios multiply, they do not add. The second positive test always increases the posterior (provided LR+>1\text{LR}^+ > 1).
  32. Ex. 79.32Understanding

    What is the practical difference between using a Beta(1,1) prior and a Beta(10,10) prior for a coin? In which case will the posterior be more sensitive to new data?

    Show solution
    The Beta(1,1) prior is uniform on [0,1][0,1] — it does not favor any value of θ\theta. The Beta(α\alpha,β\beta) prior with α,β>1\alpha,\beta > 1 concentrates mass around α/(α+β)\alpha/(\alpha+\beta). A more "informative" prior (larger α+β\alpha + \beta) requires more data to be dominated by the likelihood. With Beta(1,1) prior and n=10n = 10 observations (k heads), the posterior Beta(1+k, 1+10−k) has mean (k+1)/12(k+1)/12 — slightly pulled toward 0.5 relative to the MLE k/10k/10.
  33. Ex. 79.33Challenge

    Show that two conditionally independent positive tests given HH result in posterior odds equal to r1×r2×r_1 \times r_2 \times prior odds, where ri=LRi+r_i = \text{LR}_i^+.

    Show solution
    Via odds form: prior odds =P(H)/P(¬H)= P(H)/P(\neg H). After E1E_1: posterior1_1 odds =LR1×= \text{LR}_1 \times prior odds. After E2E_2 (with posterior1_1 as new prior): posterior2_2 odds =LR2×LR1×= \text{LR}_2 \times \text{LR}_1 \times prior odds =r1r2×= r_1 r_2 \times prior odds. Extension by induction: for nn conditionally independent pieces of evidence: posterior odds =r1r2rn×= r_1 r_2 \cdots r_n \times prior odds. The odds form turns sequential updating into multiplication of LRs.
  34. Ex. 79.34Challenge

    Demonstrate that the posterior of the Bernoulli-Beta model is Beta(α+k\alpha + k, β+nk\beta + n - k) when the prior is Beta(α\alpha, β\beta) and we observe kk successes in nn trials.

    Show solution
    See the referenced source for the detailed solution.
  35. Ex. 79.35Proof

    Demonstrate Bayes' theorem from the definition of conditional probability and the law of total probability.

    Show solution
    By definition of conditional probability: P(HiE)=P(HiE)/P(E)P(H_i \mid E) = P(H_i \cap E)/P(E). By the multiplication theorem: P(HiE)=P(EHi)P(Hi)P(H_i \cap E) = P(E \mid H_i)P(H_i). By the law of total probability (partition {H1,,Hn}\{H_1,\ldots,H_n\}): P(E)=jP(EHj)P(Hj)P(E) = \sum_j P(E \mid H_j)P(H_j). Substituting: P(HiE)=P(EHi)P(Hi)/jP(EHj)P(Hj)P(H_i \mid E) = P(E \mid H_i)P(H_i)/\sum_j P(E \mid H_j)P(H_j). \square
  36. Ex. 79.36Proof

    Show that P(AB)=P(BA)P(A)/P(B)P(A \mid B) = P(B \mid A)\,P(A)/P(B) using only the definition of conditional probability. Identify why P(AB)P(BA)P(A \mid B) \neq P(B \mid A) in general.

    Show solution
    See the referenced source for the detailed solution.
  37. Ex. 79.37Challenge

    Monty Hall problem with 3 doors. Use Bayes to calculate the probability of the car being in each door after Monty (who knows where the car is) opens an empty door. Should you switch?

    Show solution
    Monty Hall: 3 doors, car in 1. Hypotheses: H1H_1 = car in door 1 (prior 1/3), H2H_2 = door 2, H3H_3 = door 3. You choose door 1. Monty opens door 3 (no car). Evidence EE = "Monty opens door 3". P(EH1)=1/2P(E \mid H_1) = 1/2 (Monty chooses between 2 and 3 randomly), P(EH2)=1P(E \mid H_2) = 1 (can only open 3), P(EH3)=0P(E \mid H_3) = 0 (would not open with car). P(E)=1/2×1/3+1×1/3+0=1/2P(E) = 1/2 \times 1/3 + 1 \times 1/3 + 0 = 1/2. Posterior of door 1: (1/2×1/3)/(1/2)=1/3(1/2 \times 1/3)/(1/2) = 1/3. Posterior of door 2: (1×1/3)/(1/2)=2/3(1 \times 1/3)/(1/2) = 2/3. You should switch.
  38. Ex. 79.38ChallengeAnswer key

    In Naive Bayes with binary features, show that the classifier is equivalent to multiplying the individual LRs of each feature. What happens when the conditional independence assumption is violated?

    Show solution
    Naive Bayes with pp features independent given the class: P(Ckx)P(Ck)j=1pP(xjCk)P(C_k \mid \mathbf{x}) \propto P(C_k) \prod_{j=1}^p P(x_j \mid C_k). In log form: logP(Ckx)logP(Ck)+jlogP(xjCk)\log P(C_k \mid \mathbf{x}) \propto \log P(C_k) + \sum_j \log P(x_j \mid C_k). For binary features, P(xj=1Ck)=μjkP(x_j = 1 \mid C_k) = \mu_{jk}. This is equivalent to multiplying the LRs of each feature individually (if independent), exactly as in sequential updating. If features are not conditionally independent, Naive Bayes overestimates the confidence of predictions but often still classifies correctly.
  39. Ex. 79.39ProofAnswer key

    Demonstrate that the odds form of Bayes, posterior odds = LR ×\times prior odds, follows directly from the usual form of Bayes' theorem for two complementary events HH and ¬H\neg H.

    Show solution
    For the partition {H,¬H}\{H, \neg H\}: P(HE)=P(EH)P(H)/P(E)P(H \mid E) = P(E \mid H)P(H)/P(E) and P(¬HE)=P(E¬H)P(¬H)/P(E)P(\neg H \mid E) = P(E \mid \neg H)P(\neg H)/P(E). Dividing: P(HE)/P(¬HE)=[P(EH)/P(E¬H)]×[P(H)/P(¬H)]P(H \mid E)/P(\neg H \mid E) = [P(E \mid H)/P(E \mid \neg H)] \times [P(H)/P(\neg H)]. The first factor is the LR, the second is the prior odds. The normalizing factor P(E)P(E) cancels in the quotient. \square
  40. Ex. 79.40Challenge

    Show that the mean of the posterior Beta(α+k\alpha + k, β+nk\beta + n - k) converges to the maximum likelihood estimator k/nk/n when nn \to \infty, for any fixed prior Beta(α\alpha, β\beta). What does this imply about the relationship between Bayes and frequentism for large samples?

    Show solution
    With nn flips and kk heads, the MLE is θ^=k/n\hat\theta = k/n. The posterior mean with Beta(α\alpha,β\beta) is (α+k)/(α+β+n)(\alpha + k)/(\alpha + \beta + n). When nn \to \infty: (α+k)/(α+β+n)k/n(\alpha + k)/(\alpha + \beta + n) \to k/n (since k/nθk/n \to \theta by the law of large numbers and the terms α,β\alpha, \beta become negligible). For any fixed prior (with α+β\alpha + \beta finite), the posterior converges to MLE. Interpretation: with many data, the data "annihilates" the prior — this is the consistency result of Bayesian inference.

Sources

Updated on 2025-05-14 · Author(s): Clube da Matemática

Found an error? Open an issue on GitHub or submit a PR — open source forever.