Bayesians
Thinking about statistics
Principle or heuristic
Advanced
They are frequentists.
What it is
The supposed battle between Bayesians and frequentists hides a convergence. A Bayesian posterior probability is a frequency statement, averaged over a reference set of problems: all the situations where the prior and the data model hold. If the prior describes the distribution of true parameters across the problems you work on, then 90% posterior intervals contain the truth 90% of the time across those problems. Bayesians care about calibration, which is a frequentist property. They just choose a different reference set.
Why it matters
This perspective gives practical guidance. To check a Bayesian method, simulate from the prior and the model and see whether its intervals are calibrated. That is a frequency evaluation. It also clarifies disagreements. A frequentist interval is calibrated for every fixed θ, while a Bayesian interval is calibrated on average over the prior. Neither is “subjective” or “objective.” They answer differently defined frequency questions.
How it works
Let \(\theta \sim p(\theta)\) and \(y \mid \theta \sim p(y \mid \theta)\). The posterior interval \(I(y)\) with probability \(0.9\) satisfies
\[ \Pr\big(\theta \in I(y)\big) = 0.9, \]
where the probability is over the joint distribution of \((\theta, y)\). Conditional on a particular \(\theta\), coverage can be above or below 0.9. It is higher near the prior mean, because shrinkage helps there, and lower far from it. Averaged over \(\theta\) drawn from the prior, it is exactly 0.9.
Simulated example
The prior is \(\theta \sim \mathrm{N}(0, 1)\) and the data give \(y \sim \mathrm{N}(\theta, \text{se})\). For a grid of fixed true values, we compute the coverage of the Bayesian 90% interval. Then we average over θ drawn from the prior.
Show simulation code
The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.
import {rng, range, normalPosterior, mean, pct, dnorm} from "../js/stats.js"
viewof se = Inputs.range([0.2, 2], {value: 1, step: 0.1, label: "Data standard error"})
viewof seed = Inputs.range([1, 500], {value: 24, step: 1, label: "Random seed"})
coverage = {
const r = rng(seed);
const cov = theta => {
let hit = 0;
for (let k = 0; k < 800; k++) {
const y = r.normal(theta, se), post = normalPosterior(0, 1, y, se);
if (Math.abs(post.mean - theta) < 1.645 * post.sd) hit++;
}
return hit / 800;
};
const grid = range(31).map(i => -3 + i * 0.2).map(theta => ({theta, cov: cov(theta), prior: dnorm(theta)}));
let hit = 0;
for (let k = 0; k < 5000; k++) {
const theta = r.normal(0, 1), y = r.normal(theta, se), post = normalPosterior(0, 1, y, se);
if (Math.abs(post.mean - theta) < 1.645 * post.sd) hit++;
}
return {grid, averaged: hit / 5000};
}
Plot.plot({
ariaLabel: "Bayesians: simulation chart",
ariaDescription: "Horizontal axis: Fixed true θ. Vertical axis: Coverage of Bayesian 90% interval. The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 300,
x: {label: "Fixed true θ", grid: true},
y: {label: "Coverage of Bayesian 90% interval", domain: [0, 1], grid: true},
marks: [
Plot.areaY(coverage.grid, {x: "theta", y: d => d.prior, fill: "#2166ac", fillOpacity: 0.12}),
Plot.line(coverage.grid, {x: "theta", y: "cov", stroke: "#2166ac", strokeWidth: 2}),
Plot.ruleY([0.9], {stroke: "#d6604d", strokeDasharray: "4 3"}),
Plot.text([0], {x: 2.9, y: 0.93, text: () => "nominal 90%", textAnchor: "end", fill: "#d6604d"})
]
})# Bayesians are frequentists: coverage averaged over the prior.
1se <- 1 # data standard error
2set.seed(24)
# Prior N(0, 1); the 90% posterior interval for theta given y
3covers <- function(theta, y) {
w1 <- 1 / se^2
m <- w1 * y / (1 + w1)
s <- sqrt(1 / (1 + w1))
abs(m - theta) < 1.645 * s
}
grid <- seq(-3, 3, by = 0.2)
4cov_fixed <- sapply(grid, function(th) mean(covers(th, rnorm(800, th, se))))
theta <- rnorm(5000) # theta drawn from the prior
5averaged <- mean(covers(theta, rnorm(5000, theta, se)))
cat("Coverage at theta = 0: ", round(100 * cov_fixed[grid == 0]),
"%; at theta = 3: ", round(100 * cov_fixed[length(grid)]), "%\n",
sep = ""
)
cat("Averaged over the prior: ", round(100 * averaged, 1), "%\n", sep = "")
6plot(grid, cov_fixed,
type = "l", lwd = 2, col = "#2166ac", ylim = c(0, 1),
xlab = "True value of theta", ylab = "Coverage of the 90% interval"
)
polygon(c(grid, rev(grid)), c(dnorm(grid), rep(0, length(grid))),
col = adjustcolor("#2166ac", 0.12), border = NA
)
abline(h = 0.9, col = "#d6604d", lty = 2)- 1
- The page’s control: the data’s standard error.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- Whether the 90% posterior interval under a N(0, 1) prior covers the true value.
- 4
- Frequentist coverage at each fixed true value: too high near the prior’s center, too low in its tails.
- 5
- Coverage averaged over true values drawn from the prior. This is the frequency property a Bayesian interval does have.
- 6
- Coverage as a function of the true value, with the prior density shaded. The dashed line is the nominal 90%.
# Bayesians are frequentists: coverage averaged over the prior.
from statistics import NormalDist
import numpy as np
import matplotlib.pyplot as plt
se = 1 # data standard error
rng = np.random.default_rng(24)
def covers(theta, y):
"""Prior N(0, 1): does the 90% posterior interval contain theta?"""
w1 = 1 / se ** 2
m, s = w1 * y / (1 + w1), np.sqrt(1 / (1 + w1))
return np.abs(m - theta) < 1.645 * s
grid = np.round(np.arange(-3, 3.01, 0.2), 1)
cov_fixed = np.array([covers(th, rng.normal(th, se, 800)).mean()
for th in grid])
theta = rng.normal(size=5000) # theta drawn from the prior
averaged = covers(theta, rng.normal(theta, se)).mean()
print(f"Coverage at theta = 0: {100 * cov_fixed[grid == 0][0]:.0f}%; "
f"at theta = 3: {100 * cov_fixed[-1]:.0f}%")
print(f"Averaged over the prior: {100 * averaged:.1f}%")
prior = np.array([NormalDist().pdf(t) for t in grid])
plt.fill_between(grid, prior, color="#2166ac", alpha=0.12)
plt.plot(grid, cov_fixed, color="#2166ac", linewidth=2)
plt.axhline(0.9, color="#d6604d", linestyle="--")
plt.ylim(0, 1)
plt.xlabel("True value of theta")
plt.ylabel("Coverage of the 90% interval")
plt.show()Key takeaways
- Bayesian probabilities are calibrated frequencies over the reference set defined by the prior.
- Frequentist and Bayesian coverage answer different “over what?” questions, and both are frequency claims.
- Check Bayesian methods by simulation from the prior: if the intervals are calibrated there, the machinery works.
Source
- Andrew Gelman, Bayesians are frequentists (2018).