Objective
The Bayesian Updating with Repeated Evidence lesson compared hypotheses with no free parameters (which die, which coin) using likelihood ratios. Real models have parameters: "the strategy has zero edge" against "the strategy has some edge of unknown size". This lesson shows how to compare such models, why the comparison automatically penalises flexibility, how this connects to BIC, and why a Bayes factor and a p-value can point in opposite directions. By the end you should be able to compute a Bayes factor for a coin by hand and explain Lindley's paradox in an interview.
Marginal likelihood and Bayes factors
The marginal likelihood (or evidence) of model averages the likelihood over that model's prior:
Posterior odds between two models are prior odds times the Bayes factor:
A common reading (Kass and Raftery, 1995): of 1–3 is barely worth mentioning, 3–20 positive, 20–150 strong, above 150 very strong.
The Occam effect. is a probability distribution over possible data sets, so it sums to one. A flexible model that can explain many data sets must spread its probability thinly; a sharp model concentrates it. If the data land where the sharp model predicted, it wins, even though the flexible model fits at least as well at its best parameter. The penalty is not added by hand; it falls out of averaging the likelihood instead of maximising it.
The coin
Compare : against : , after a particular sequence of flips with heads:
(Using the count instead of the sequence multiplies both by , so the Bayes factor is the same.) A neat fact: under the number of heads is uniform on , with probability each. commits to nothing, and pays for it.
Worked example
ten flips
For flips, compute for heads and compare with the two-sided exact p-value for fairness.
Show solutionHide solution
throughout. For : , so . For : and .
| Heads | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|
| 0.37 | 0.44 | 0.78 | 2.07 | 9.31 | 93.1 | |
| Two-sided p-value | 1.000 | 0.754 | 0.344 | 0.109 | 0.021 | 0.002 |
Read the Occam effect from the first columns. At 6 heads the best-fitting fits better than , yet the evidence favours the fair coin by to 1, because wasted prior mass on values like that predicted these data badly. Only from about 8 heads does the flexible model pay its way.
Compare the scales: gives , "significant at 5%", but a Bayes factor of 9: with even prior odds, the posterior probability of a biased coin is , not . A p-value is not the probability of the null, and it typically overstates the evidence against it.
BIC is a Laplace approximation to the evidence
Expand the log integrand around the maximum likelihood estimate (dimension ). The likelihood is approximately Gaussian with precision matrix , so
Dropping the terms gives with . So , with an error that does not shrink as grows: it converges to a constant that depends on the prior. BIC is consistent for choosing the model, but it is a crude evidence calculator.
The code compares the exact log Bayes factor for the coin with the BIC version when 60% of flips are heads.
from math import lgamma, log
def log_bf10_exact(k, n): # uniform prior on p vs p = 1/2
log_m1 = lgamma(k + 1) + lgamma(n - k + 1) - lgamma(n + 2)
log_m0 = n * log(0.5)
return log_m1 - log_m0
def log_bf10_bic(k, n): # max log-lik gain minus (1/2) log n
p = k / n
gain = k * log(p) + (n - k) * log(1 - p) - n * log(0.5)
return gain - 0.5 * log(n)
print(" n heads exact BIC diff")
for n in (10, 100, 1_000, 10_000):
k = int(0.6 * n) # always 60% heads
e, b = log_bf10_exact(k, n), log_bf10_bic(k, n)
print(f"{n:6d} {k:6d} {e:7.2f} {b:7.2f} {e - b:6.3f}")
Output:
n heads exact BIC diff
10 6 -0.81 -0.95 0.136
100 60 -0.09 -0.29 0.198
1000 600 16.89 16.68 0.205
10000 6000 196.96 196.75 0.205
The gap settles at , exactly the term dropped above. Note also how the evidence moves: at 60 heads in 100 the models are roughly tied, while 600 in 1,000 is overwhelming.
Lindley's paradox
Fix the z-statistic and let grow. For the coin, under the count is uniform, , while under the normal approximation gives . Hence
For a normal mean with , and , the exact version is
Either way, at fixed the Bayes factor for the null grows like . A result that is "significant" at a fixed level eventually becomes strong evidence for the null. This is Lindley's paradox, and it is not a contradiction: the two methods answer different questions. With fixed, the estimated effect shrinks like , and a tiny effect is better predicted by "exactly zero" than by an alternative that spread its prior over effects thousands of times larger.
Two practical consequences:
- The prior under the alternative matters, and does not wash out. For large , is roughly proportional to : doubling the prior SD of the effect roughly doubles the evidence for the null, while the posterior for under barely moves. Choose on the scale of effects you actually consider plausible. In trading, edges are tiny, so a vague alternative is a poor model of "the strategy works".
- No improper priors on parameters that differ between models. A flat prior makes proportional to an arbitrary , and so is the Bayes factor. Parameters common to both models (a shared variance, say) can take improper priors, because the constant cancels.
Worked example
a million flips
A coin lands heads times in flips. Compute the z-statistic and two-sided p-value for fairness, and against a uniform alternative.
Show solutionHide solution
Frequentist. Under the count has mean and SD , so and the two-sided p-value is . Reject fairness at 5%.
Bayesian. . The exact calculation with gives . With even prior odds, .
Reconciling them. The estimate is very close to a half. The data are about as consistent with as data can be at this sample size, whereas the uniform alternative said, before seeing anything, that was as likely to be in as in . Against a sharper alternative, say , the normal formula with gives and , about 5 to 1 for bias. The Bayes factor depends on what "biased" was supposed to mean.
Posterior model averaging
Choosing one model and then acting as if it were true ignores the uncertainty about which model is right. Bayesian model averaging (BMA) weights each model's answer by its posterior probability:
For prediction, BMA has lower expected log-loss than any single model when the model set and priors are right. In return-predictability research it is used to average over subsets of candidate predictors, which tempers the inflated in-sample fit of the single best subset.
Computing evidence is hard outside conjugate models. The harmonic-mean estimator from MCMC output is notoriously unstable; bridge sampling, nested sampling or thermodynamic integration are the reliable options. If the goal is predictive accuracy rather than identifying a true model, cross-validation or approximate leave-one-out (PSIS-LOO, WAIC) is often preferred; it is far less sensitive to the prior width than the Bayes factor.
Worked example
averaging over the coin models
With even prior odds, you see 8 heads in 10 flips. What is the predictive probability that the next flip is heads under each model, under the selected model, and under BMA?
Show solutionHide solution
Model probabilities. , so and .
Within-model predictions. : . : the posterior is , so (Laplace's rule).
Select versus average. Selecting predicts . BMA predicts
BMA is less extreme because a third of the posterior weight is still on the fair coin. If you bet at even money with the Kelly fraction , the difference matters: says stake 50% of the bankroll, says 34%, so acting on the selected model bets about half as much again as the averaged estimate justifies.
Knowledge check
A coin is flipped 10 times and lands heads 9 times. What is the Bayes factor for : against : ?
Knowledge check
You test whether a strategy's mean daily return is zero using 2,500 days, daily SD 1%, and get z = 2.2. Analyst A puts a N(0, 0.1%^2) prior on the mean under the alternative; analyst B uses N(0, 1%^2). What do their Bayes factors say?
Knowledge check
Hold the z-statistic of a test at 2.5 and increase the sample size from one million to one hundred million, with a fixed uniform alternative. What happens to the Bayes factor in favour of the null?
Key takeaways
- The evidence averages the likelihood over the prior; the Bayes factor is the ratio of evidences, and posterior odds = prior odds × Bayes factor.
- Averaging rather than maximising builds in an Occam penalty: 6 heads in 10 favours the fair coin by 2.3 to 1 even though fits better.
- BIC is a Laplace approximation with an error that never vanishes; it is consistent for model choice but crude for the evidence.
- Lindley's paradox: at fixed , grows like . P-values and Bayes factors answer different questions.
- Bayes factors are sensitive to the prior width under the alternative and are undefined with improper priors on model-specific parameters; choose priors on the scale of plausible effects.
- Model averaging weights predictions by posterior model probabilities and is less over-confident than selecting a single model.
Practice problems
Finished reading?
Answer the 3 knowledge checks to complete this lesson (0 done).