Search

Search papers and lessons

Bayesian Model Averaging

Level 4 · 10 min read

Bayesian model averaging predicts with several candidate models at once, weighting each by how well it explained the data, instead of betting on a single winner.

On this page

  • Colour = topic mix
  • Probability
  • Inference
  • Sign in to see your progress

TL;DR

Bayesian model averaging (BMA) makes a prediction by asking several candidate models at once and mixing their answers. Each model gets a weight equal to its posterior probability, which combines how well it explained the data with how plausible it was before the data arrived. Models that explain the data poorly fade out smoothly instead of being discarded by a hard choice.

Picking one best model throws away the uncertainty about which model is right. BMA keeps that uncertainty and carries it into the prediction, so the answer is usually less overconfident.

Where you'll see it: in model selection for regression and forecasting, in ensembles whose members are weighted by their evidence, and in Bayesian variable selection.

Intuition

Do not bet on one model

Suppose three doctors look at the same patient and offer three diagnoses: a virus, a bacterial infection, an allergy. Picking one doctor at random ignores the disagreement. Trusting the most famous doctor ignores it too, and the cost is high if that doctor is wrong. A better approach is to weigh each diagnosis by how much its reasoning holds up, and act on the weighted combination.

BMA does this for statistical models. A "model" here is a full recipe: a family of probability distributions plus a prior over its parameters, such as "a straight line with Gaussian noise" or "a quadratic with Gaussian noise". Data arrives, each recipe is scored by how well it accounted for that data, and the prediction for something new is the average over recipes, weighted by those scores.

The score is the evidence, not the fit

The score that matters is not the best fit to the data. A flexible model can always fit the observed points more closely, but a closer fit does not make it a better explanation. The score BMA uses is the probability the model assigned to the observed data, averaged over every parameter value the model allows. A model that spreads its bets over many possibilities pays for the ones the data does not support. This is a built-in Occam's razor: flexibility that the data does not use is penalised.

00.20.40.60.810123p, the chance of headsdensity
  • posterior over p under M2
Model M2 says the coin's chance p is unknown, with a uniform prior. After seven heads in ten flips its posterior is a Beta(8,4) curve that peaks at p = 0.7. A model that fixes p at 0.5 would put all its belief at one point.

The math

Definition: Bayesian model averaging
Given data DD and candidate models M1,…,MKM_1, \ldots, M_K, the predictive distribution for a new observation y∗y^\ast is the average of the models' predictions, weighted by the posterior probability of each model: P(y∗∣D)=∑k=1KP(y∗∣D,Mk) P(Mk∣D)P(y^\ast \mid D) = \sum_{k=1}^{K} P(y^\ast \mid D, M_k)\, P(M_k \mid D).

Where the sum comes from

Start from the law of total probability over the models. Assume exactly one of the candidates is the true one, so the events "model kk is true" split all possibilities between them, and

P(y∗∣D)=∑k=1KP(y∗,Mk∣D)=∑k=1KP(y∗∣D,Mk) P(Mk∣D).P(y^\ast \mid D) = \sum_{k=1}^{K} P(y^\ast, M_k \mid D) = \sum_{k=1}^{K} P(y^\ast \mid D, M_k)\, P(M_k \mid D).

The second step is the product rule applied to each term: the probability of y∗y^\ast and MkM_k together is the probability of MkM_k times the probability of y∗y^\ast given MkM_k, with DD held on the right of every bar. The factor P(y∗∣D,Mk)P(y^\ast \mid D, M_k) is simply what model kk alone would predict after seeing the data, for example by averaging its likelihood over its own posterior for θ\theta.

Posterior model probabilities

The weights are a Bayes' rule update where the hypothesis is the model:

P(Mk∣D)=P(D∣Mk) P(Mk)∑j=1KP(D∣Mj) P(Mj).P(M_k \mid D) = \frac{P(D \mid M_k)\, P(M_k)}{\sum_{j=1}^{K} P(D \mid M_j)\, P(M_j)}.

Here P(Mk)P(M_k) is the prior probability of model kk, often the same for every model. P(D∣Mk)P(D \mid M_k) is the evidence (also called the marginal likelihood) for model kk. The denominator is the same for every kk, so it only normalises the weights to sum to 1.

The evidence

The evidence averages the likelihood over the model's own parameters θ\theta:

P(D∣Mk)=∫P(D∣θ,Mk) P(θ∣Mk) dθ.P(D \mid M_k) = \int P(D \mid \theta, M_k)\, P(\theta \mid M_k)\, d\theta.

This is where the Occam effect lives. The integrand is large only where the parameters both fit the data and are plausible under the prior. A flexible model has a prior spread over a large region, so most of its prior mass sits where the data is unlikely.

Working in logs

Evidence values are often tiny, so they underflow if multiplied directly. Let ℓk=log⁡P(D∣Mk)+log⁡P(Mk)\ell_k = \log P(D \mid M_k) + \log P(M_k) and ℓmax⁡=max⁡kℓk\ell_{\max} = \max_k \ell_k. Then

P(Mk∣D)=exp⁡(ℓk−ℓmax⁡)∑jexp⁡(ℓj−ℓmax⁡).P(M_k \mid D) = \frac{\exp(\ell_k - \ell_{\max})}{\sum_{j} \exp(\ell_j - \ell_{\max})}.

Subtracting the largest log value leaves the weights unchanged but keeps every exponent at zero or below.

The BIC approximation

When the integral has no closed form, a common shortcut is the Bayesian information criterion. With θ^k\hat\theta_k the maximum likelihood estimate, pkp_k the number of free parameters in model kk, and nn the number of observations,

log⁡P(D∣Mk)≈log⁡P(D∣θ^k,Mk)−pk2log⁡n.\log P(D \mid M_k) \approx \log P(D \mid \hat\theta_k, M_k) - \frac{p_k}{2} \log n.

This comes from a Laplace approximation (replacing the integrand by a Gaussian bump centred on its peak), and it becomes accurate as nn grows. With equal model priors, the weights are then proportional to exp⁡(−BICk/2)\exp(-\mathrm{BIC}_k / 2).

Worked examples

Example
Two coin models, seven heads in ten flips

Model M1M_1: the coin is fair, so p=0.5p = 0.5. Model M2M_2: pp is unknown, with a uniform prior on [0,1][0, 1]. Both models have prior probability 1/21/2. The data is one specific sequence of ten flips with seven heads.

  1. Evidence under M1M_1. There are no parameters to integrate over, so P(D∣M1)=0.510=1/1024≈0.000977P(D \mid M_1) = 0.5^{10} = 1/1024 \approx 0.000977.
  2. Evidence under M2M_2. With a uniform prior (density 1), P(D∣M2)=∫01p7(1−p)3 dpP(D \mid M_2) = \int_0^1 p^7 (1-p)^3\, dp. This integral is the Beta function B(8,4)B(8,4), which equals 7! 3!11!=11320≈0.000758\dfrac{7!\,3!}{11!} = \dfrac{1}{1320} \approx 0.000758. The same integrand, divided by B(8,4)B(8,4), is the Beta(8,4) posterior over pp used in step 5.
  3. Bayes factor. P(D∣M1)/P(D∣M2)=1320/1024≈1.29P(D \mid M_1) / P(D \mid M_2) = 1320/1024 \approx 1.29, so the data mildly favours the fair coin. The flexible model spreads its prior over every value of pp, and most of those values are a poor match for seven heads.
  4. Posterior weights. P(M1∣D)=1.29/(1+1.29)≈0.563P(M_1 \mid D) = 1.29 / (1 + 1.29) \approx 0.563, and P(M2∣D)≈0.437P(M_2 \mid D) \approx 0.437.
  5. Prediction that the next flip is heads. Under M1M_1 it is 0.50.5. Under M2M_2 the posterior for pp is Beta(8,4), with mean 8/12≈0.6678/12 \approx 0.667. The mixture gives 0.563×0.5+0.437×0.667≈0.281+0.291≈0.5730.563 \times 0.5 + 0.437 \times 0.667 \approx 0.281 + 0.291 \approx 0.573.

Interpretation: the best single model says 0.50.5, and the flexible model's posterior mean says 0.6670.667. BMA answers 0.5730.573. That is a hedged number, and it reflects the fact that the data cannot yet tell the two models apart.

Example
Three regression models with close evidence

Three models predict a sales figure: AA is linear, BB is quadratic, CC is cubic. Equal prior on each. Suppose their log evidences, computed by integration or by BIC, are log⁡P(D∣A)=−120.0\log P(D \mid A) = -120.0, log⁡P(D∣B)=−118.5\log P(D \mid B) = -118.5, and log⁡P(D∣C)=−125.0\log P(D \mid C) = -125.0.

  1. Subtract the largest value, −118.5-118.5. The shifted values are A:−1.5A: -1.5, B:0B: 0, C:−6.5C: -6.5.
  2. Exponentiate. We get e−1.5≈0.2231e^{-1.5} \approx 0.2231, e0=1e^{0} = 1, and e−6.5≈0.0015e^{-6.5} \approx 0.0015.
  3. Normalise. The sum is 1.22461.2246, so the weights are A:0.182A: 0.182, B:0.817B: 0.817, C:0.001C: 0.001.
  4. Predictions for the new input are A:10.0A: 10.0, B:12.0B: 12.0, C:11.0C: 11.0. The BMA prediction is 0.182×10+0.817×12+0.001×11≈11.630.182 \times 10 + 0.817 \times 12 + 0.001 \times 11 \approx 11.63.

Interpretation: the quadratic dominates, but the linear model still pulls the answer down from 12.012.0 to 11.6311.63, because it has real weight. The cubic is effectively switched off. Its log evidence is 6.56.5 nats lower than the quadratic's, which means about e6.5≈665e^{6.5} \approx 665 times less evidence, so its prediction barely counts.

Tradeoffs and failure modes

BMA is principled, but it only answers the question you asked. It is also not the same as ensembling by Bagging, which trains members on resampled data and averages them with equal weight. BMA's weights come from a probability argument about the models, and the members usually see the same data.

SituationWhat goes wrongBetter choice
The true model is not in the candidate setThe weights only compare the models you wrote down, so the average can be confidently wrongAdd more candidates, and treat the weights as relative, not absolute
Parameter priors are diffuse or chosen casuallyEvidence depends heavily on the prior, so a model can lose weight just because its prior is wideUse weakly informative priors and check how the weights change
The integral has no closed formExact evidence is expensive or impossibleBIC or Laplace approximations, Importance Sampling, or bridge sampling with Markov Chain Monte Carlo
Many models with negligible weightsCompute is spent on members that add nothingKeep only the top models, or drop those far below the best (Occam's window)
Predictive accuracy is the real goalEvidence measures how well the prior predicted the data, which can disagree with held-out accuracyCompare models with cross-validation and weight them by their held-out performance

History

Harold Jeffreys set out Bayes factors for comparing hypotheses in his 1939 book Theory of Probability. In 1978 Edward Leamer's book on specification searches in econometrics argued that ignoring model uncertainty leads to conclusions that are too confident. Through the 1990s Adrian Raftery and colleagues made averaging practical, promoting BIC-based approximations and Occam's window to drop implausible models. Computing the sums and integrals for larger models became feasible as sampling methods improved. The 1999 tutorial by Hoeting, Madigan, Raftery and Volinsky gathered the method and its practical issues, and it became the standard reference. The idea caught on because it turned an argument about which model to trust into a calculation that reports how much trust is warranted.

Check yourself

QuestionWhat is the difference between choosing the single best model and Bayesian model averaging?Show answer

Choosing the best model predicts with one model MkM_k and discards the others, along with the uncertainty about which one is right. Bayesian model averaging gives every candidate a weight equal to its posterior probability P(Mk∣D)P(M_k \mid D), and the prediction is the weighted average of all their predictions. When one model dominates, BMA is close to the best-model choice. When several fit about equally well, BMA spreads the answer across them and reports the disagreement through the mixture.

QuestionTwo models have evidence P(D∣A)=0.02P(D \mid A) = 0.02 and P(D∣B)=0.08P(D \mid B) = 0.08, with equal prior probability. Model A predicts 3.03.0 for a new input and model B predicts 5.05.0. What is the BMA prediction?Show answer

The posterior weights are P(A∣D)=0.02/(0.02+0.08)=0.2P(A \mid D) = 0.02 / (0.02 + 0.08) = 0.2 and P(B∣D)=0.8P(B \mid D) = 0.8. The BMA prediction is 0.2×3.0+0.8×5.0=0.6+4.0=4.60.2 \times 3.0 + 0.8 \times 5.0 = 0.6 + 4.0 = 4.6. Model B dominates because it explains the data four times better, but the answer is pulled towards A, not set to 5.05.0.

QuestionWhy does the evidence penalise a model that could fit the data more closely?Show answer

The evidence averages the likelihood over the model's prior on its parameters. A more flexible model spreads its prior over many parameter values, and most of them do not explain the observed data well. Its average likelihood can therefore be lower than a simpler model's, even when its best single fit is higher. Flexibility the data does not need costs probability, which is the Occam effect built into the calculation.

QuestionYou fit a model with 20 parameters and a model with 2 parameters to n=1000n = 1000 points. Their maximised log likelihoods are −1500-1500 and −1530-1530. Which model does BIC prefer, and how much weight does it get under equal model priors?Show answer

BIC is −2log⁡L+plog⁡n-2 \log L + p \log n. For the 20-parameter model, 3000+20×log⁡1000≈3000+138.2=3138.23000 + 20 \times \log 1000 \approx 3000 + 138.2 = 3138.2. For the 2-parameter model, 3060+2×log⁡1000≈3060+13.8=3073.83060 + 2 \times \log 1000 \approx 3060 + 13.8 = 3073.8. The lower BIC wins, so the 2-parameter model is preferred. The difference is 3138.2−3073.8=64.43138.2 - 3073.8 = 64.4, and the weights are proportional to exp⁡(−BIC/2)\exp(-\mathrm{BIC}/2), so the ratio is e32.2e^{32.2} in favour of the simpler model. Its weight is effectively 11, and the 20-parameter model contributes nothing to the average.

Sources