Maximum likelihood and Bayesian parameter estimation
Methods to estimate unknown parameters from data using Maximum Likelihood (MLE) and Bayesian (prior→posterior) approaches, with derivations, formulas and worked examples useful for exam preparation.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Engineers use parameter estimation to build probabilistic pattern-recognition models (for example in Bayesian decision theory or classifiers). Maximum Likelihood (MLE) gives point estimates from data only; Bayesian estimation combines data with prior knowledge and gives a full posterior distribution useful for uncertainty-aware decisions and the posterior predictive distribution used in classification.
Key ideas
Start with clear definitions and assumptions.
Parameter: a numeric quantity θ (could be vector) that controls a probability model p(x | θ). Unit: depends on the model and parameter (e.g., for Gaussian, μ has same unit as x, σ² has unit²; probabilities are unitless; rate parameters have reciprocal units).
Model / Likelihood model: a family of probability density or mass functions {p(x | θ) : θ ∈ Θ} assumed to generate observed data x. Example: Gaussian family N(μ, σ²).
Data: observations x = (x1, x2, ..., xN), assumed IID (independent and identically distributed) from p(x | θ) unless stated otherwise. Explicitly state IID assumption when used.
Likelihood: For parameter θ and observed data x, the likelihood is L(θ; x) = p(x | θ). For IID data, L(θ; x) = ∏_{i=1..N} p(xi | θ). Note: the likelihood as a function of θ is not a probability distribution in θ (it does not integrate to 1 over θ).
Maximum Likelihood Estimate (MLE): the value θ̂ML that maximises the likelihood L(θ; x) (or equivalently the log-likelihood). Formally: **θ̂_ML = argmax{θ ∈ Θ} p(x | θ)**. Assumptions: model is correct or good enough; data are IID.
Typical derivation steps for MLE (exam style):
- Write joint likelihood L(θ) = ∏ p(xi | θ) assuming IID.
- Take log-likelihood l(θ) = ln L(θ) to convert product → sum.
- Differentiate l(θ) w.r.t θ, set derivative(s) = 0, solve for θ.
- Check second derivative (or Hessian) to confirm a maximum.
Example standard MLE results (you will derive these in exams):
- For IID Gaussian with unknown mean μ and known variance σ²: μ̂_ML = (1/N) ∑ xi.
- For IID Gaussian with unknown μ and σ² both unknown: μ̂_ML = (1/N) ∑ xi and σ̂²_ML = (1/N) ∑ (xi − μ̂)² (note: MLE variance divides by N; unbiased sample variance divides by N−1).
- For IID Bernoulli(p) with k successes in N trials: p̂_ML = k/N.
Bayesian parameter estimation: treat θ as a random variable with a prior distribution p(θ). After seeing data x, update to the posterior by Bayes' rule:
p(θ | x) = p(x | θ) p(θ) / p(x), where p(x) = ∫ p(x | θ) p(θ) dθ is the evidence or marginal likelihood.
- Posterior combines prior belief and data; it is a probability distribution over θ (unlike likelihood).
- Maximum a posteriori (MAP) estimate: θ̂MAP = argmax{θ} p(θ | x). If prior is uniform, MAP = MLE.
- Posterior predictive distribution for a new observation x_new is p(x_new | x) = ∫ p(x_new | θ) p(θ | x) dθ. This integrates parameter uncertainty into predictions.
Conjugate prior: a prior p(θ) is a conjugate prior for likelihood p(x | θ) if the posterior p(θ | x) is in the same family as the prior. Examples: Beta prior for Bernoulli likelihood (Beta→Beta), Dirichlet prior for Multinomial, Normal prior for Normal mean with known variance. Also common: Gamma prior for Poisson or Exponential rate (Gamma→Gamma), Normal–Inverse-Gamma prior for Normal with unknown mean and variance, and in the multivariate case Normal–Wishart/Normal–Inverse-Wishart. For Dirichlet–Multinomial the posterior predictive implements additive smoothing: p(x_new=j | x) = (n_j + α_j) / (N + ∑_k α_k).
Marginal likelihood / model evidence p(x): used for model comparison (Bayes factor). Compute by integrating the likelihood weighted by prior.
Diagrams to draw (exam instruction):
- Draw a horizontal axis labelled θ (parameter). Plot three curves on same plot: prior p(θ) (label), likelihood L(θ) (label; scale arbitrary), and posterior p(θ | x) (label). Show that posterior ∝ prior × likelihood. Mark θ̂_ML at likelihood peak and θ̂_MAP at posterior peak; if prior is flat, they coincide. Draw arrows from data to likelihood and from prior to posterior.
- For Gaussian parameter estimation: draw normal density of data and indicate sample mean and sample variance on the x-axis.
Assumptions to state explicitly in derivations: IID data, form of likelihood family (e.g., Gaussian, Bernoulli), and when using conjugate priors, the prior hyperparameters are given.
Formulas
L(θ; x) = p(x | θ) = ∏_{i=1..N} p(xi | θ)
- xi: observed data points, unit = unit of data (e.g., m for meters); θ: parameter(s); applies when observations are IID.
l(θ) = ln L(θ; x) = ∑_{i=1..N} ln p(xi | θ)
- Natural log of likelihood; same symbols as above; useful because products → sums.
θ̂_ML = argmax_{θ ∈ Θ} L(θ; x) = argmax_{θ ∈ Θ} l(θ)
- The MLE, unit = unit of θ; applies for parametric estimation under assumed model.
p(θ | x) = p(x | θ) p(θ) / p(x)
- p(θ | x): posterior; p(θ): prior; p(x): evidence = ∫ p(x | θ) p(θ) dθ; probabilities are unitless.
θ̂_MAP = argmax_{θ} p(θ | x) = argmax_{θ} [ln p(x | θ) + ln p(θ)]
- MAP estimate includes prior term; applies in Bayesian point estimation.
p(x_new | x) = ∫ p(x_new | θ) p(θ | x) dθ
Posterior predictive; units: if x_new is continuous this is a density with units 1/(unit of x_new), and if x_new is discrete it is unitless; used when predicting new observations.
Common conjugate pairs (formulas):
Bernoulli/Binomial likelihood: if x denotes the full IID sequence, p(x | p) = ∏_{i=1..N} p^{xi} (1−p)^{1−xi} = p^k (1−p)^{N−k}; if x denotes only the count k, then p(k | p) = C(N,k) p^k (1−p)^{N−k} (the combinatorial factor does not depend on p).
- k = number of successes in N trials; p unitless; applies to IID Bernoulli/Binomial data.
Beta prior: p(p) ∝ p^{α−1} (1−p)^{β−1}
- α, β > 0 are hyperparameters; unitless; posterior is Beta(α + k, β + N − k).
Gaussian likelihood (known variance σ²): p(x | μ) = ∏ (1/√(2πσ²)) exp(−(xi−μ)²/(2σ²))
- μ has same unit as xi; σ² is variance (unit²); applies for IID normal data with known variance.
MLE for Gaussian mean (σ² known): μ̂_ML = (1/N) ∑ xi
- Sample mean; unit same as data.
MLE for Gaussian variance (μ unknown): σ̂²_ML = (1/N) ∑ (xi − μ̂)²
- MLE variance divides by N (biased estimator for population variance); unit = (data unit)².
Worked examples
Example 1 — MLE for Gaussian mean and variance (numerical) Problem: Given N = 5 IID measurements (in metres): x = [1.05, 0.95, 1.10, 1.00, 0.90] m, assume data ~ N(μ, σ²) with both μ and σ² unknown. Find μ̂_ML and σ̂²_ML.
Step 1 — sample mean (formula then numbers):
μ̂_ML = (1/N) ∑ xi
Numbers: μ̂ = (1.05 + 0.95 + 1.10 + 1.00 + 0.90) / 5 = 5.00 / 5 = 1.00 m.
Step 2 — MLE variance (formula then numbers):
σ̂²_ML = (1/N) ∑ (xi − μ̂)²
Compute squared deviations: (1.05−1.00)²=0.0025, (0.95−1.00)²=0.0025, (1.10−1.00)²=0.01, (1.00−1.00)²=0, (0.90−1.00)²=0.01.
Sum = 0.0025+0.0025+0.01+0+0.01 = 0.025.
Divide by N=5: σ̂²_ML = 0.025 / 5 = 0.005 m². So σ̂_ML = sqrt(0.005) = 0.07071 m.
Final answers: μ̂_ML = 1.00 m; σ̂²_ML = 0.005 m² (note: unbiased sample variance would use N−1=4 giving 0.00625 m²).
Example 2 — Bayesian Beta-Bernoulli (numerical) Problem: Prior belief for coin bias p is Beta(α=2, β=3). We observe N=8 tosses with k=5 heads. Find posterior and predictive probability of next toss being head.
Step 1 — posterior Beta parameters: posterior is Beta(α + k, β + N − k) = Beta(2+5, 3+3) = Beta(7, 6).
Step 2 — posterior mean (used for predictive): E[p | data] = (α + k) / (α + β + N) = 7 / (7+6) = 7/13 ≈ 0.53846.
Step 3 — posterior predictive probability of head on next toss equals posterior mean = 0.53846 (unitless).
So posterior = Beta(7,6), predictive head probability = 0.53846.
Example 3 — MAP for Gaussian mean with known variance (derivation + numeric) Problem: Data xi IID N(μ, σ²) with known σ² = 1 (unit²). Prior for μ is N(μ0 = 0.5, σ0² = 0.25). Observed N = 3 data: x = [1.0, 0.8, 1.2]. Find μ̂_MAP.
Derivation (standard): posterior p(μ | x) ∝ exp(−∑(xi−μ)²/(2σ²)) · exp(−(μ−μ0)²/(2σ0²)). Completing the square gives μ̂_MAP = ( (N/σ²) * x̄ + (1/σ0²) * μ0 ) / (N/σ² + 1/σ0² ).
Compute numbers: x̄ = (1.0+0.8+1.2)/3 = 3.0/3 = 1.0. Weights: N/σ² = 3/1 = 3, 1/σ0² = 1/0.25 = 4. So μ̂_MAP = (31.0 + 40.5) / (3 + 4) = (3 + 2) / 7 = 5/7 ≈ 0.71429.
Answer: μ̂_MAP = 0.71429 (same unit as data).
Common mistakes
- Using MLE variance formula with division by N−1 (confuse unbiased estimator with MLE which divides by N).
- Not stating IID assumption when deriving joint likelihood.
- In Bayesian updates, forgetting to update hyperparameters correctly for conjugate priors (e.g., Beta update α→α+k, β→β+N−k).
- For MAP, failing to include the prior term (equivalently using MLE) or using an improper prior without checking normalization.
- Numerically, not checking second derivative / concavity to confirm maxima.
For your exam
Question types you will get about this topic:
- Definitions and short notes: define likelihood, MLE, prior, posterior, conjugate prior, MAP, posterior predictive.
- Derivations: derive MLE for Gaussian mean and variance, derive MLE for Bernoulli, derive MAP for Gaussian mean with Gaussian prior.
- Numericals: compute MLE from given data, update Beta prior with observed successes, compute posterior predictive.
- Diagrams: draw prior, likelihood and posterior curves and label MLE and MAP.
What a full-marks answer includes:
- Clear statement of assumptions (IID, model family).
- Correct formulation of likelihood and log-likelihood.
- Correct differentiation and algebra to find extrema, with second-derivative test or argument for maximum.
- For Bayesian problems: correct prior, posterior expression, and normalization or use of conjugate update formula; include final numeric answers with units where applicable.
- For predictive questions: show integration for p(x_new | x) and evaluate (for conjugate pairs, show closed form).
Quick check
- For N IID Bernoulli trials with k successes, what is the MLE of p?
- If prior for p is Beta(1,1) and observed k successes in N trials, what is the posterior?
- For Gaussian data with known variance, what is the effect of a Gaussian prior on the mean in the MAP estimate?
Answers: 1) p̂_ML = k/N. 2) Posterior = Beta(1+k, 1+N−k). 3) MAP is a weighted average of sample mean and prior mean: μ̂_MAP = ((N/σ²) x̄ + (1/σ0²) μ0) / (N/σ² + 1/σ0²); the prior shifts the estimate towards μ0 depending on its precision (1/σ0²).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?