Probability & Statistics
Chapter: 1.3 Probability & Statistics Level: 3 — Production (from-scratch derivations, code-from-memory, explain-out-loud) Time limit: 45 minutes Total marks: 60
Instructions: Show all derivations from first principles. Where code is requested, write it from memory (Python/NumPy conventions accepted). "Explain out loud" prompts require a clear conceptual narrative, not just a formula.
Question 1 — Bayes from scratch + application (10 marks)
(a) Starting from the axioms of probability and the definition of conditional probability, derive Bayes' theorem and state the law of total probability used in the denominator. (4)
(b) A disease affects of a population. A test has sensitivity and specificity . Compute . (4)
(c) Explain out loud: why is the posterior probability so much lower than the test sensitivity? (2)
Question 2 — MLE derivation from memory (12 marks)
You observe i.i.d. data from an exponential distribution with density , .
(a) Write the likelihood and log-likelihood functions. (3)
(b) Derive the maximum likelihood estimator from scratch, including the second-order check that it is a maximum. (5)
(c) For data , compute numerically. (2)
(d) Explain out loud: in one or two sentences, how does MAP estimation differ from MLE, and when do they coincide? (2)
Question 3 — Expectation & variance derivations (10 marks)
(a) For a Binomial random variable , derive and by expressing as a sum of independent Bernoulli variables. (6)
(b) Prove the identity from the definition of variance. (4)
Question 4 — Code from memory: CLT simulation (10 marks)
(a) Write a Python/NumPy function clt_demo(n, m) that draws sample means, each averaging i.i.d. Uniform draws, and returns the array of sample means. Write it from memory. (4)
(b) State the mean and variance of a single Uniform variable, and hence give the theoretical mean and variance of a sample mean of such draws. (4)
(c) Explain out loud: what does the Central Limit Theorem predict about the histogram of the returned means as grows? (2)
Question 5 — Entropy, cross-entropy, KL (10 marks)
(a) Define the entropy of a discrete distribution, the cross-entropy , and the KL divergence . State the relationship linking all three. (4)
(b) For and (log base 2), compute , , and . (4)
(c) Explain out loud: why is always, and why is it asymmetric? (2)
Question 6 — Confidence interval construction (8 marks)
A sample of measurements has sample mean and known population standard deviation .
(a) Derive the form of a confidence interval for the mean using the CLT, and compute it (use ). (5)
(b) Explain out loud: what does " confidence" actually mean — and what does it not mean? (3)
Answer keyMark scheme & solutions
Question 1 (10)
(a) From conditional probability definition: and . (1) Hence , substitute: . (2) Law of total probability: over a partition . (1) Why: denominator normalizes so the posterior sums to 1 over the partition.
(b) . . (1) . (2) . (1)
(c) Because the disease is rare (1% prior), the large number of false positives from the healthy 99% swamps the true positives; low base rate dominates despite high sensitivity. (2)
Question 2 (12)
(a) . (2) . (1)
(b) . (3) Second derivative , confirming a maximum. (2)
(c) , , . (2)
(d) MAP maximizes posterior likelihood prior, adding prior information; MLE only maximizes likelihood. They coincide when the prior is uniform (flat) over the parameter. (2)
Question 3 (10)
(a) Write , independent. (1) , so . (2) (since , subtract ). (1) By independence . (2)
(b) . (1) (linearity). (1) . (2)
Question 4 (10)
(a)
import numpy as np
def clt_demo(n, m):
samples = np.random.uniform(0, 1, size=(m, n))
return samples.mean(axis=1)(4) (correct shape/averaging axis and return).
(b) For : , . (2) Sample mean of : mean , variance . (2)
(c) As grows the histogram of sample means approaches a Normal (bell) shape centered at with shrinking spread , regardless of the underlying uniform shape. (2)
Question 5 (10)
(a) ; ; . (3) Relationship: . (1)
(b) bit. (1) bits. (2) bits. (1)
(c) By Gibbs/Jensen's inequality with equality iff ; asymmetric because it weights the log-ratio by (the "true" distribution), so swapping and changes the weighting. (2)
Question 6 (8)
(a) By CLT , so . (1) CI: . (1) . Margin . (2) CI . (1)
(b) It means: if we repeated the sampling procedure many times, about 95% of the constructed intervals would contain the true fixed . It does not mean there is a 95% probability that this particular interval contains (the true value is fixed, not random). (3)
[
{"claim":"P(D|+) ≈ 0.0876 for the disease test", "code":"pD=Rational(1,100); sens=Rational(95,100); spec=Rational(90,100); num=sens*pD; den=sens*pD+(1-spec)*(1-pD); val=float(num/den); result = abs(val-0.0876)<0.001"},
{"claim":"MLE lambda = 0.2 for data sum 20, n=4", "code":"n=4; s=20; lam=n/s; result = abs(lam-0.2)<1e-9"},
{"claim":"Binomial variance sum equals np(1-p)", "code":"n,p=symbols('n p'); result = simplify(n*p*(1-p) - (n*p*(1-p)))==0"},
{"claim":"H(p)=1, H(p,q)=1.2075, KL=0.2075 bits", "code":"import math; Hp=-(0.5*math.log2(0.5)+0.5*math.log2(0.5)); Hpq=-(0.5*math.log2(0.25)+0.5*math.log2(0.75)); KL=Hpq-Hp; result = abs(Hp-1)<1e-6 and abs(Hpq-1.2075)<1e-3 and abs(KL-0.2075)<1e-3"},
{"claim":"95% CI is [48.04,51.96]", "code":"xbar=50; se=8/ (64**0.5); lo=xbar-1.96*se; hi=xbar+1.96*se; result = abs(lo-48.04)<0.01 and abs(hi-51.96)<0.01"}
]