Exercises — Bayesian statistics — prior, likelihood, posterior (intro)
Before we start, one reminder of our four characters (we will use these words with no further apology):
Level 1 — Recognition
Goal: name the pieces. No arithmetic beyond a fraction.
Exercise 1.1. In the sentence "I believed a coin was fair, then I flipped 8 heads in 10, and now I think it's biased," label which clause is the prior, which is the likelihood-driven evidence, and which is the posterior.
Recall Solution 1.1
- Prior = "I believed a coin was fair" — belief before data, so peaked at .
- Likelihood = "I flipped 8 heads in 10" — this is the data , and asking how probable it is for each is .
- Posterior = "now I think it's biased" — updated belief after data, shifted toward larger .
Exercise 1.2. Which of these is a probability distribution over (integrates to in ): the prior , the likelihood , or the posterior ? Pick all that apply.
Recall Solution 1.2
The prior and the posterior are genuine distributions over — each integrates to . The likelihood is not: it is a function of but a probability of the data. It has no reason to integrate to over . (This is the single most common confusion in the whole subject — see the Maximum Likelihood Estimation note for the frequentist cousin that just maximises this function.)
Exercise 1.3. Fill the cloze. The identity ==posterior likelihood prior== drops which term, and why is dropping it allowed?
Recall Solution 1.3
It drops the evidence . Dropping is allowed because does not depend on — for the purpose of finding the shape of the posterior in , it is just a constant. You put it back at the very end by normalising.
Level 2 — Application
Goal: plug numbers into Bayes' theorem correctly.
Exercise 2.1 (discrete, two hypotheses). A factory has two machines. Machine A makes of parts with a defect rate; Machine B makes with a defect rate. A random part is defective. What is ?
Recall Solution 2.1
Let , . Priors: . Likelihoods: . Evidence (by the Law of Total Probability): Posterior: So despite A making most parts, a defective part is more likely from B () because B is dirtier.
Exercise 2.2 (odds form). Same numbers as 2.1. Compute the posterior odds of A versus B and confirm they match. (Posterior odds prior odds likelihood ratio.)
Recall Solution 2.2
Prior odds . Likelihood ratio . Posterior odds , i.e. . Convert to probability: . ✓ Matches 2.1 — the evidence cancels entirely in the ratio, which is exactly why odds form is convenient.
Exercise 2.3 (repeat the earlier disease test with a twist). Prevalence ; test is sensitive () and specific (). You test positive. Find .
Recall Solution 2.3
, , . About 16% — again the small prior keeps it low, though less brutally than the case in the parent note.
Level 3 — Analysis
Goal: reason about the machinery, not just crank it.
Exercise 3.1 (sequential updating = order doesn't matter). Start with prior . You see data , update to a posterior, then see independent data and update again. Show algebraically that the final posterior equals what you'd get updating on and together, and that the order of does not matter.
Recall Solution 3.1
After : . Use this as the new prior and update on (independent given , so ): Batch update on both at once: Identical. And since multiplication commutes, swapping changes nothing — today's posterior is tomorrow's prior, and the arrival order is irrelevant (see the figure).

Exercise 3.2 (why the mean shrinks). A coin gives heads in tosses with a prior. The posterior is with mean . Show this mean is always a weighted average of the prior mean and the data fraction , and say what the weights are.
Recall Solution 3.2
Let (prior "strength") and write: Check: expand the right side . ✓ The weights and sum to . Interpretation: the prior counts as "pseudo-observations." As , and the data wins — the connection to Frequentist vs Bayesian Inference. (This uses the Beta Distribution as conjugate to the Binomial Distribution.)
Exercise 3.3 (numerical shrinkage). With prior (mean ) and data heads in , compute the posterior, its mean, and confirm the mean lies strictly between and .
Recall Solution 3.3
Posterior . Mean . Weights: , . Check: . ✓ And indeed .
Level 4 — Synthesis
Goal: combine several ideas into one coherent argument.
Exercise 4.1 (two positive tests). Disease prevalence ; a test is sensitive and specific (). You test positive twice with two independent tests. Find by using the first posterior as the second prior.
Recall Solution 4.1
First update (from the parent note): . Second update — new prior , so : Two positives push belief from to . The likelihood ratio applied twice: prior odds , giving . ✓
Exercise 4.2 (three-hypothesis coin). A drawer has three coins: fair (), biased-heads (), two-headed (), chosen with priors . You flip once and get heads. Find the posterior over the three coins.
Recall Solution 4.2
Likelihoods : . Unnormalised posteriors (likelihood × prior): Evidence . Posterior: One heads nudges probability mass toward the head-favouring coins, but the fair coin's larger prior keeps it (barely) in the lead. This discrete-hypothesis pattern is exactly the engine inside a Naive Bayes Classifier.
Level 5 — Mastery
Goal: prove/derive something general and interpret limits.
Exercise 5.1 (posterior with a full continuous prior — no conjugacy shortcut). A coin's bias has prior density on (a : you lean toward heads). You observe 1 head in 1 toss. Derive the posterior density exactly by integrating the evidence yourself, then give the posterior mean.
Recall Solution 5.1
Likelihood of "1 head" is . Unnormalised posterior: . Evidence (integrate over all , the continuous Law of Total Probability): Posterior: Check it's a density: . ✓ This is — consistent with conjugacy (). Posterior mean .
Exercise 5.2 (limiting behaviour of a vague prior). For a prior with data heads in tosses, show that as (an increasingly "vague" prior), the posterior mean approaches the pure data fraction — the Maximum Likelihood Estimation answer. State the degenerate case where this breaks.
Recall Solution 5.2
Posterior mean . Let : So the vague-prior Bayesian mean coincides with the frequentist MLE — the bridge in Frequentist vs Bayesian Inference. Degenerate case: if additionally (no data), the limit is — undefined, because with a vague prior and no observations you have literally no information to form a mean. Also if or with tiny , the posterior piles almost all mass at an endpoint ( or ), giving an over-confident "the coin is certainly two-tailed/two-headed" — the well-known danger of ML-style estimates on extreme small samples.
Exercise 5.3 (prior-vs-data tug of war, quantitative). With data , you want the posterior mean to land exactly at . Using a prior whose mean is (so ), find the prior strength that achieves it.
Recall Solution 5.3
With , posterior mean . Solve: , so , giving . Prior (strength pseudo-observations, i.e. as much weight as the real ). Check: posterior , mean . ✓ To pull the estimate halfway from the data fraction toward the prior mean , the prior must carry exactly as many pseudo-counts as you have real data — the tug-of-war of Exercise 3.2 made concrete.
Recall One-line self-audit before you leave
Can you, without looking, state: (1) which of prior/likelihood/posterior is not a distribution over ; (2) why the disease posterior is so low; (3) why sequential and batch updates agree; (4) what "prior strength" controls? (1) likelihood ::: (2) rare disease ⇒ false positives swamp true positives ::: (3) likelihoods multiply and multiplication commutes, so order-independent and equal to the joint update ::: (4) how many pseudo-observations the prior is worth — i.e. how much data it takes to move it.