Foundations to Frontier
Tests
A. Mathematical Foundations › A5 Statistics › Bayesian statistics

Model Comparison: Bayes Factors, Marginal Likelihood, BIC, AIC, WAIC

More complex models always fit the training data better, so how do you choose? The Bayesian answer is the marginal likelihood (evidence), which automatically penalizes flexibility (Occam's razor) and gives Bayes factors between models. BIC approximates it; AIC and WAIC instead estimate out-of-sample predictive accuracy. You will compute all of them for polynomial degree selection, see Bayes factors quantify evidence for a null as well as against it, meet Lindley's paradox, and compare sensor-noise models with WAIC from posterior draws.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

The wiggly line that fits too well

Draw a curve through 10 noisy measurements. A straight line misses some points. A crazy wiggly curve can pass through every point exactly, but it’ll predict the next measurement terribly. A good model is as simple as possible but no simpler.

Model comparison methods score models by how well they fit and how much they had to stretch to do it. A flexible model that could have fitted almost anything gets less credit when it fits your data.

How complex should the model be? AIC, BIC and the evidence
train RMSE
falls forever
AIC
★ degree 7
BIC
★ degree 3
−2 log evidence
★ degree 3
0123456789
Bars run over polynomial degree 0–9 (each criterion rescaled to its own range; lower is better). Training error always decreases, so it can't choose. AIC penalizes 2 per parameter, BIC log n per parameter, and the Bayesian evidence integrates over the coefficients (prior sd 2), an automatic Occam's razor. Green dashed: the truth. Orange: the evidence-selected fit.
Why engineers care

Is the motor’s friction linear or does it need a Stribeck term? Is sensor noise Gaussian or heavy-tailed? How many layers or components does a model need? Choosing complexity well prevents both underfitting and overfitting.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A more complex model always…
  2. 2. Model comparison rewards…
  3. 3. A curve through every noisy point usually…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Information criteria

With maximized log-likelihood ℓ^\hat\ell, kk parameters and nn data points:

  • AIC =−2ℓ^+2k= -2\hat\ell + 2k estimates the out-of-sample predictive log-score (Akaike, 1974). It aims at good prediction.
  • BIC =−2ℓ^+klog⁡n= -2\hat\ell + k\log n approximates −2log⁡-2\log evidence (Schwarz, 1978). It’s consistent for the true model if that model is among the candidates.

Lower is better. ΔAIC or ΔBIC of 2 is weak evidence, 6 is strong, and 10 is very strong. Akaike weights wi∝e−Δi/2w_i\propto e^{-\Delta_i/2} express relative support.

Bayes factors

BF10=p(x∣M1)p(x∣M0),P(M1∣x)P(M0∣x)⏟posterior odds=BF10×P(M1)P(M0)⏟prior odds\text{BF}_{10} = \frac{p(x\mid M_1)}{p(x\mid M_0)}, \qquad \underbrace{\frac{P(M_1\mid x)}{P(M_0\mid x)}}_{\text{posterior odds}} = \text{BF}_{10}\times\underbrace{\frac{P(M_1)}{P(M_0)}}_{\text{prior odds}}

Unlike a p-value, a Bayes factor can favour the null. For 52 heads in 100 tosses, “fair coin” vs “unknown bias (uniform prior)” gives BF01≈7.4\text{BF}_{01}\approx7.4: positive evidence that the coin is fair.

📝 Quick check (Level 1)
0/3 answered
  1. 1. BIC's penalty per parameter is…
  2. 2. BF₁₀ = 3 with prior odds 1 gives P(M₁ | data) =
  3. 3. Can a Bayes factor provide evidence for the null?

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.

The marginal likelihood and Occam’s razor

p(x∣M)=∫p(x∣θ,M) p(θ∣M) dθp(x\mid M) = \int p(x\mid\theta, M)\,p(\theta\mid M)\,d\theta

It’s the average fit over the prior, not the best fit. A flexible model spreads its prior probability over many possible datasets, so it assigns each one less: the Occam factor. With a Laplace approximation, log⁡p(x∣M)≈ℓ^+log⁡p(θ^)+k2log⁡2π−12log⁡det⁡H\log p(x\mid M)\approx\hat\ell + \log p(\hat\theta) + \frac k2\log2\pi - \frac12\log\det H. With det⁡H∝nk\det H\propto n^k, this gives ℓ^−k2log⁡n+O(1)\hat\ell - \frac k2\log n + O(1), which is BIC.

For Bayesian linear regression it’s exact: y∼N(0,σ2I+τ2XX⊤)y\sim\mathcal N(0, \sigma^2I + \tau^2XX^\top). In Exercise 1, the evidence picks the true polynomial degree about 84% of the time, BIC 80%, and AIC 60%. AIC errs toward complexity by design.

WAIC and cross-validation

When predictive accuracy is the goal, estimate the expected log predictive density on new data:

  • LOO-CV: ∑ilog⁡p(xi∣x−i)\sum_i\log p(x_i\mid x_{-i}).
  • WAIC (Watanabe, 2010): −2(lppd−pWAIC)-2(\text{lppd} - p_{\text{WAIC}}), where lppd=∑ilog⁡1S∑sp(xi∣θ(s))\text{lppd} = \sum_i\log\frac1S\sum_sp(x_i\mid\theta^{(s)}) and pWAIC=∑iVar⁡slog⁡p(xi∣θ(s))p_{\text{WAIC}} = \sum_i\operatorname{Var}_s\log p(x_i\mid\theta^{(s)}). It’s computed from posterior draws, valid for singular models (mixtures, neural networks), and asymptotically equal to LOO. PSIS-LOO is the robust practical version (Vehtari, Gelman and Gabry, 2017).

Sensitivity to priors

Bayes factors depend strongly on the priors of the parameters being compared: a vaguer prior means a lower evidence. Predictive criteria (WAIC, LOO) are much less sensitive. Use Bayes factors when the priors are meaningful, and predictive criteria otherwise.

🐍 Exercise 1: choosing polynomial degree, and Bayes factors
Compute the log-likelihood, AIC, BIC and the exact Bayesian marginal likelihood for polynomial fits of degree 0–8. Over 200 datasets, measure how often each criterion picks the true degree. Compute Bayes factors for a fair coin vs unknown bias.
📝 Quick check (Level 2)
0/3 answered
  1. 1. The marginal likelihood is the likelihood…
  2. 2. BIC approximates…
  3. 3. WAIC is computed from…

Level 3: Advanced

★★★★☆ Advanced⏱ 45 minGraduate level, with full derivations and proofs.

Deriving BIC

Laplace’s method gives ∫eℓ(θ)p(θ)dθ≈eℓ^p(θ^)(2π)k/2det⁡(nI)−1/2\int e^{\ell(\theta)}p(\theta)d\theta\approx e^{\hat\ell}p(\hat\theta)(2\pi)^{k/2}\det(nI)^{-1/2}. Taking logs, log⁡p(x)≈ℓ^−k2log⁡n+[log⁡p(θ^)+k2log⁡2π−12log⁡det⁡I]\log p(x)\approx\hat\ell - \frac k2\log n + \big[\log p(\hat\theta) + \frac k2\log2\pi - \frac12\log\det I\big]. The bracket is O(1)O(1) as n→∞n\to\infty. So −2log⁡p(x)≈−2ℓ^+klog⁡n-2\log p(x)\approx-2\hat\ell + k\log n. ∎

Why AIC targets prediction

The expected out-of-sample log-likelihood of the MLE is Eℓ^−k+o(1)\mathbb E\hat\ell - k + o(1). The in-sample ℓ^\hat\ell is optimistic by about kk, the trace of J−1IJ^{-1}I for a correct model. Correcting gives AIC/(−2). Under misspecification the correction is tr⁡(J−1K)\operatorname{tr}(J^{-1}K) (Takeuchi’s TIC). WAIC’s pWAICp_{\text{WAIC}} estimates it automatically, which is why pWAICp_{\text{WAIC}} moves away from kk for a misspecified model (Exercise 2).

Lindley’s paradox

Test H0:μ=0H_0: \mu = 0 against H1:μ∼N(0,τ2)H_1: \mu\sim\mathcal N(0, \tau^2) with xˉ∼N(μ,1/n)\bar x\sim\mathcal N(\mu, 1/n). For a fixed z=nxˉz = \sqrt n\bar x,

BF01=1+nτ2 exp⁡(−z22nτ21+nτ2)→∞  as n→∞\text{BF}_{01} = \sqrt{1 + n\tau^2}\,\exp\Big(-\frac{z^2}2\frac{n\tau^2}{1 + n\tau^2}\Big)\to\infty\ \text{ as }n\to\infty

A “significant” z=2z = 2 (p = 0.046) becomes strong evidence for the null at large n, because the effect size it implies is tiny compared with what H1H_1 predicted (Lindley, 1957). p-values and Bayes factors answer different questions.

Exercise 3.1: Derive the fair-coin Bayes factor

p(k∣12)=(nk)2−np(k\mid\frac12) = \binom nk2^{-n} and p(k∣U)=∫01(nk)pk(1−p)n−kdp=(nk)B(k+1,n−k+1)=1n+1p(k\mid U) = \int_0^1\binom nkp^k(1 - p)^{n-k}dp = \binom nkB(k + 1, n - k + 1) = \frac1{n + 1}. The ratio is 2−n/B(k+1,n−k+1)2^{-n}/B(k + 1, n - k + 1).

📝 Quick check (Level 3)
0/3 answered
  1. 1. In-sample log-likelihood overestimates out-of-sample performance by about…
  2. 2. Lindley's paradox: fixed z, growing n makes BF₀₁…
  3. 3. Under misspecification the correct penalty is…

Level 4: Expert

★★★★★ Expert⏱ 40 minResearchers: original papers and open problems.

Which noise model for encoder residuals?

Joint-encoder residuals combine quantization and jitter. Are they Gaussian or Laplace? Each model has one scale parameter with a conjugate posterior. Drawing from both posteriors and computing WAIC picks the Laplace model on Laplace data and the Gaussian on Gaussian data. For the correct model, pWAIC≈1p_{\text{WAIC}}\approx1, while the misspecified Gaussian fit to heavy-tailed data shows pWAIC≈3.7p_{\text{WAIC}}\approx3.7, a symptom of misfit. The same workflow compares dynamics models, kernel choices and network architectures, provided posterior (or ensemble) draws are available.

🐍 Exercise 2 (research): WAIC for sensor-noise model choice
Draw from the conjugate posteriors of zero-mean Gaussian and Laplace noise models, compute pointwise log-likelihoods and WAIC, and show that WAIC picks the generating model on both Laplace and Gaussian residuals. Then check p_WAIC for the correct and misspecified models.

Model comparison in AI, robotics and aerospace

  • Hyperparameter learning. Maximizing the marginal likelihood (type-II ML) fits GP kernels and Bayesian regression priors (A4.4-6; MacKay, 1992).
  • Structure selection in system identification. Model order of ARX/state-space models by AIC/BIC (Ljung, 1999). Number of mixture components by BIC (A4.2-6).
  • Multiple-model estimation. IMM filters compute running model likelihoods, effectively Bayes factors between motion modes (Blom and Bar-Shalom, 1988).
  • Bayesian deep learning. Model selection by approximate evidence, for example Laplace approximations for architectures and priors (Immer et al., 2021). Ensembles are compared by predictive log-likelihood.
  • Scientific hypothesis testing with Bayes factors (Kass and Raftery, 1995), for example “is this telemetry trend real?” with priors on plausible drift rates.

References

  1. H. Akaike (1974). “A new look at the statistical model identification.” IEEE Transactions on Automatic Control, 19(6).
  2. G. Schwarz (1978). “Estimating the dimension of a model.” Annals of Statistics, 6(2).
  3. R. Kass, A. Raftery (1995). “Bayes factors.” JASA, 90(430).
  4. S. Watanabe (2010). “Asymptotic equivalence of Bayes cross validation and widely applicable information criterion in singular learning theory.” JMLR, 11.
  5. A. Vehtari, A. Gelman, J. Gabry (2017). “Practical Bayesian model evaluation using leave-one-out cross-validation and WAIC.” Statistics and Computing, 27.
  6. D. Lindley (1957). “A statistical paradox.” Biometrika, 44(1/2).
  7. D. MacKay (1992). “Bayesian interpolation.” Neural Computation, 4(3).
  8. K. Burnham, D. Anderson (2002). Model Selection and Multimodel Inference, 2nd ed. Springer.
  9. L. Ljung (1999). System Identification: Theory for the User, 2nd ed. Prentice Hall.
  10. A. Immer, M. Bauer, V. Fortuin, G. Rätsch, M. E. Khan (2021). “Scalable marginal likelihood estimation for model selection in deep learning.” ICML.