TL;DR
A model with an unknown setting can explain the same data in many ways. The marginal likelihood is one number that says how well the whole model explains the data: the likelihood of each setting, averaged over all settings with the weights given by the prior. A setting that fits well counts for a lot only if the prior gave it real weight. The same number is the denominator of Bayes' rule, and it is the score used to choose between models.
Where you'll see it: in deciding whether a fair coin or an unknown bias better explains a run of flips, in picking the width of a prior from the data (Empirical Bayes), and in tuning the settings of a Bayesian model, such as how much noise to assume in the data.
Intuition
The denominator you could ignore
In the posterior lesson the denominator of Bayes' rule was called a normaliser, a number that makes the weights add to one. It has a meaning of its own. Bayes' rule says
The evidence answers a question you can ask before you know the setting at all: under this model, before anyone tells me which setting is true, how probable was the data I actually saw?
Averaging, not picking
The maximum likelihood approach asks which single setting explains the data best, and reports that setting's score. The marginal likelihood asks something broader. It scores every setting, then averages those scores, weighting each one by how plausible the prior said it was before the data.
Think of a weather forecaster who holds a model with three possible climates, dry, mixed and wet, and who does not know which one holds. Today's rainfall gets a score under each climate. The forecaster's overall score for the model is the average of those three scores, weighted by how plausible each climate was beforehand. A climate that explains today well raises the average only as much as its prior weight allows.
- likelihood of 3 heads and 2 tails
Why it acts as a referee
A model with many free settings can fit many datasets. If it spreads its prior over settings that do not match the data, the average falls. A simpler model that puts its weight where the data lands gets a higher average even though it fits less tightly. This is the Occam effect: complexity is not punished by a rule added on top, it is punished automatically by the averaging.
flowchart LR A[Model with unknown setting] --> B[Prior weights over settings] B --> C[Likelihood of the data at each setting] C --> D[Average over settings] D --> E[Marginal likelihood: score of the whole model] E --> F[Denominator of Bayes' rule] E --> G[Comparison between models]
The math
Definition
For a model with unknown parameter and observed data , the marginal likelihood, also called the model evidence, is
The integrand is the likelihood times the prior , both read for the model . The integral adds up that product over every value of (the definite integral over the whole range). The result no longer depends on : the setting has been averaged out, which is why the name is "marginal". If takes only a few values, the integral becomes a sum with the same meaning, as in the Law of Total Probability:
The denominator of Bayes' rule
Apply Bayes' rule to the setting inside a fixed model:
The denominator is the marginal likelihood. This is the same that the posterior lesson wrote as a sum or integral over the settings. Computing it is the hard step in Bayesian inference, because it means summing or integrating over every setting, which is why Markov Chain Monte Carlo and variational methods exist.
Comparing two models
Put a prior on the models too. For two models and , Bayes' rule applied to models gives
The denominators of the two posteriors cancel, so the evidence is the only thing the data contribute. Its ratio is the Bayes factor. Posterior odds equal the Bayes factor times the prior odds. Notice that the comparison needs no separate test set, because each model's score already accounts for its own flexibility.
Closed forms and approximations
For some pairs of prior and likelihood, the integral can be done by hand. A Conjugate Prior pair is the standard case: the prior and posterior have the same family, so the marginal likelihood is a ratio of known functions. In general there is no closed form. Two routes are used in practice. Sampling gives the posterior, and estimating the evidence from samples is harder than estimating the posterior itself. Variational methods give a lower bound on the log evidence, the evidence lower bound.
Worked examples
A coin's heads chance is one of , or , each with prior weight . You flip once and get heads. The likelihood of heads at setting is itself.
- Likelihoods: , and .
- Weight each by its prior and add: .
- So the marginal likelihood is .
- Posteriors, as the Bayes' rule formula gives them: , and . They add to 1.
Interpretation: for one flip, the evidence equals the prior average of , which here is . The model predicted heads with that chance on average, and heads is what happened. The posterior moves weight toward , because it explains the heads best.
Use a uniform prior on over , so the prior density is there. The data are three heads and two tails in that order. (Orderings are the same for every , so they can be left out of the likelihood.)
- Likelihood at : .
- Marginal likelihood: .
- Expand the integrand: .
- Integrate term by term: .
- For comparison, the best single setting is , with likelihood .
Interpretation: the evidence is less than half of the best single score . Most values of explain three heads in five flips poorly, and the uniform prior gives each of them equal weight. The average includes those poor explanations, so it comes out lower than the peak.
Two models describe the same five flips, three heads and two tails. Model 1 says the coin is fair, so with no free setting. Model 2 has an unknown with the uniform prior from the previous example. Give both models equal prior weight.
- Model 1 has no setting to average over: .
- Model 2 is the integral from the previous example: .
- Bayes factor: .
- With equal prior weights, the posterior odds favour the fair coin about 1.9 to 1.
Interpretation: Model 2 fits the data better at its best setting, since beats . It still loses, because its prior spends weight on biases such as that these five flips rule out. The simpler model is not penalised for being simple; it is rewarded for not wasting its prior. The evidence picks up that trade-off automatically.
A sensor reads a true value with noise, so one reading is where . Before any reading, the prior for is , with a width you must choose. One reading arrives: . Which width does the data support better, or ?
- The reading is plus independent Gaussian noise, so . Variances add, as in the Gaussian sums rule.
- The density of at is .
- For , : .
- For , : .
- Ratio: in favour of the wide prior.
Interpretation: the tight prior says is almost certainly near zero, so a reading of 3 looks surprising under it. The wide prior spreads belief and makes 3 plausible, and the data prefer it by about 7 to 1. Choosing by maximising this evidence is the idea behind Empirical Bayes. With one reading the comparison is weak; more readings make it sharper.
Tradeoffs and failure modes
The evidence is exact, but it is only as meaningful as the model and prior behind it. Its weak points are different from those of a point estimate.
| Situation | What goes wrong | Better choice |
|---|---|---|
| A very wide prior on a setting | The evidence falls for every model with that setting, so the comparison reflects the arbitrary width | Use a prior with a justified scale, and check how the ranking changes when the width changes |
| Two models with different priors | The evidence depends on the prior as much as on the data | State both priors, and report the sensitivity of the comparison |
| The integral has no closed form | The evidence is expensive or impossible to get exactly | A Conjugate Prior pair, a variational bound or sampling-based estimates |
| The goal is predicting new data | Evidence measures how well the prior anticipated the data, which can disagree with held-out accuracy | Compare by Cross-Validation, or average predictions with Bayesian Model Averaging |
| The prior is improper (its total does not sum to a finite number) | The evidence is defined only up to an arbitrary constant, so comparisons are meaningless | Use a proper prior that integrates to one |
The Occam effect is real, but it is a tilt in the scores, not a verdict. If a complex model is true, a diffuse prior can still make it lose to a simple one with little data. That is why the evidence should be read together with the prior it was computed under.
History
Harold Jeffreys used the ratio of two evidences to test scientific hypotheses in the 1930s, and he set it out in Theory of Probability (first published in 1939). The ratio later became known as the Bayes factor. For much of the mid-twentieth century the method was seen as an alternative to frequentist testing, and it was considered hard to compute for anything beyond simple models.
In the early 1990s David MacKay showed that, for neural networks, the evidence gives an automatic Occam's razor: a model can be compared with others using only the training data, without a separate test set. This made the marginal likelihood a practical tool in machine learning, and the name "model evidence" spread with it. Modern methods that estimate the evidence by sampling or by variational bounds are an answer to the same old difficulty: the integral over settings.
Recap
The marginal likelihood is the likelihood averaged over every setting a model allows, with the prior as the weights. It is the denominator of Bayes' rule, so it normalises the posterior. Its ratio between two models is the Bayes factor, which decides between them without a test set, and it rewards models whose prior lands on settings the data support. It leads to Empirical Bayes, where the prior's own settings are chosen by maximising the evidence, and to the evidence lower bound, which makes the evidence tractable in large models.
Check yourself
QuestionRecall: how does the marginal likelihood differ from the likelihood at a single setting?Show answer
The likelihood at one setting is a score for that setting alone. The marginal likelihood averages the likelihood over all settings, weighted by the prior, so it scores the whole model and no longer depends on the setting.
QuestionComputation: a model has prior weight 0.25 on hypothesis H1 and 0.75 on H2. The data have likelihood 0.8 under H1 and 0.2 under H2. What is the marginal likelihood, and what is the posterior probability of H1?Show answer
The marginal likelihood is . The posterior for H1 is .
QuestionWhy: a model that contains a simpler one as a special case always fits its best setting at least as well as the simpler one. Why can it still have the lower marginal likelihood?Show answer
The evidence averages over settings, weighted by the prior. A flexible model spends prior weight on many settings that the data do not support, and those poor settings drag the average down. The simpler model puts its weight where the data are, so its average can be higher even though its best single fit is worse.
QuestionApplied: you are fitting a polynomial and must choose its degree. Lower training error keeps favouring higher degrees. Why might the marginal likelihood give a better choice, and what must you specify to compute it?Show answer
Training error always improves as the degree grows, so it cannot signal overfitting. The marginal likelihood penalises a degree whose prior spreads over coefficients the data do not need. To compute it you must specify the prior on the coefficients and the noise level, and you should check that the chosen degree is stable when those priors change.
Sources
- Bayes factor (Wikipedia): https://en.wikipedia.org/wiki/Bayes_factor
- Bayes' theorem (Wikipedia): https://en.wikipedia.org/wiki/Bayes%27_theorem
- Bishop, Pattern Recognition and Machine Learning, §3.4: https://www.microsoft.com/en-us/research/publication/pattern-recognition-machine-learning/