Bayesian
Thinking about statistics
Law or aphorism
Intermediate
A statistician who uses Bayesian inference for all problems even when it is inappropriate. I am a Bayesian statistician myself.
What it is
The definition is a self-aware joke. In the source post Gelman writes: “Every statistician uses Bayesian inference when it is appropriate (that is, when there is a clear probability model for the sampling of parameters). A Bayesian statistician is someone who will use Bayesian inference for all problems, even when it is inappropriate. I am a Bayesian statistician myself (for the usual reason that, even when inappropriate, Bayesian methods seem to work well).” He suggests the joke may be inspired by the saying that “any fool can convict a guilty man; what distinguishes a great prosecutor is the ability to convict an innocent man.”
So the twist is that Gelman embraces the label, because in practice Bayesian methods often work well even outside the cases where they are strictly justified. The joke still has a point: whether a method is appropriate depends on the problem, and it’s worth knowing when you are relying on “it seems to work” rather than on a clear probability model.
Why it matters
Applying any tool to every problem means you will sometimes be outside the conditions where it is justified, and you should know when that is happening. For Bayesian inference, one way “seems to work well” can fail is a prior that encodes confident but wrong information. The posterior then inherits the error, and its narrow intervals hide it. Treating “Bayesian” as an identity makes it harder to notice when a simpler method, a weaker prior or a non-Bayesian check would serve better.
How it works
With a normal prior \(\theta \sim \mathrm{N}(\mu_0, \sigma_0^2)\) and data giving \(\hat\theta \sim \mathrm{N}(\theta, \text{se}^2)\), the posterior mean is a precision-weighted average of \(\mu_0\) and \(\hat\theta\), with posterior sd \((\sigma_0^{-2} + \text{se}^{-2})^{-1/2}\). If the prior is centered far from the truth and is narrow, the posterior is pulled toward the wrong value with false confidence. Interval coverage falls well below nominal. A wide prior, or a check of how the prior compares with the data, guards against this.
Simulated example
We repeat an estimation problem 500 times with the true value fixed. Compare the coverage of the data-only 90% interval with that of the Bayesian 90% posterior interval, as the prior’s center moves away from the truth and the prior becomes more confident.
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, pct} from "../js/stats.js"
viewof priorOff = Inputs.range([0, 3], {value: 1.5, step: 0.1, label: "Prior center minus truth"})
viewof priorSd = Inputs.range([0.1, 3], {value: 0.4, step: 0.05, label: "Prior sd (confidence)"})
viewof se = Inputs.range([0.1, 2], {value: 0.5, step: 0.05, label: "Data standard error"})
viewof seed = Inputs.range([1, 500], {value: 23, step: 1, label: "Random seed"})
bayesReps = {
const r = rng(seed);
const truth = 0;
return range(500).map(k => {
const est = r.normal(truth, se);
const post = normalPosterior(truth + priorOff, priorSd, est, se);
return {
k,
dataCover: Math.abs(est - truth) < 1.645 * se,
bayesCover: Math.abs(post.mean - truth) < 1.645 * post.sd,
est, post: post.mean
};
});
}
Plot.plot({
ariaLabel: "Bayesian: simulation chart",
ariaDescription: "Horizontal axis: Point estimate. Vertical axis: Replications. The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 260,
x: {label: "Point estimate", grid: true},
y: {label: "Replications"},
color: {legend: true, domain: ["Data only", "Bayesian posterior mean"], range: ["#8a8a8a", "#2166ac"]},
marks: [
Plot.rectY(bayesReps, Plot.binX({y: "count"}, {x: "est", fill: () => "Data only", fillOpacity: 0.5, thresholds: 40})),
Plot.rectY(bayesReps, Plot.binX({y: "count"}, {x: "post", fill: () => "Bayesian posterior mean", fillOpacity: 0.6, thresholds: 40})),
Plot.ruleX([0], {stroke: "currentColor", strokeWidth: 2}),
Plot.ruleX([priorOff], {stroke: "#d6604d", strokeDasharray: "4 3"}),
Plot.ruleY([0])
]
})# Bayesian: a confident prior in the wrong place.
1prior_off <- 1.5 # prior center minus truth
prior_sd <- 0.4 # prior sd (confidence)
se <- 0.5 # data standard error
2set.seed(23)
truth <- 0
est <- rnorm(500, truth, se)
w0 <- 1 / prior_sd^2
w1 <- 1 / se^2
3post_mean <- (w0 * (truth + prior_off) + w1 * est) / (w0 + w1)
4post_sd <- sqrt(1 / (w0 + w1))
cat("Coverage of nominal 90% intervals: data only ",
round(100 * mean(abs(est - truth) < 1.645 * se)), "%, Bayesian ",
5 round(100 * mean(abs(post_mean - truth) < 1.645 * post_sd)), "%\n",
sep = ""
)
breaks <- seq(min(est, post_mean) - 0.1, max(est, post_mean) + 0.1,
length.out = 41
)
6hist(est,
breaks = breaks, col = adjustcolor("#2166ac", 0.5),
border = "white", main = "", xlab = "Estimate", ylab = "Replications"
)
hist(post_mean,
breaks = breaks, col = adjustcolor("#d6604d", 0.6),
border = "white", add = TRUE
)
abline(v = truth, lwd = 2)
abline(v = prior_off, col = "#d6604d", lty = 2)
legend("topright", c("Data only", "Bayesian posterior mean"),
fill = adjustcolor(c("#2166ac", "#d6604d"), 0.6), bty = "n"
)- 1
- The page’s controls: how far the prior’s center sits from the truth, how confident the prior is, and the data’s standard error.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- The posterior mean, a precision-weighted average of the prior center and the estimate. A confident prior in the wrong place pulls it off the truth.
- 4
- The posterior standard deviation is smaller than the data’s, so the interval is narrower, whether or not it is in the right place.
- 5
- Coverage of the Bayesian 90% interval, compared with the data-only interval printed just before.
- 6
- Histograms of the data-only estimates and the posterior means, with the truth as a solid line and the prior center dashed.
# Bayesian: a confident prior in the wrong place.
import numpy as np
import matplotlib.pyplot as plt
prior_off = 1.5 # prior center minus truth
prior_sd = 0.4 # prior sd (confidence)
se = 0.5 # data standard error
rng = np.random.default_rng(23)
truth = 0
est = rng.normal(truth, se, 500)
w0, w1 = 1 / prior_sd ** 2, 1 / se ** 2
post_mean = (w0 * (truth + prior_off) + w1 * est) / (w0 + w1)
post_sd = np.sqrt(1 / (w0 + w1))
data_cover = np.mean(np.abs(est - truth) < 1.645 * se)
bayes_cover = np.mean(np.abs(post_mean - truth) < 1.645 * post_sd)
print(f"Coverage of nominal 90% intervals: data only {100 * data_cover:.0f}%,"
f" Bayesian {100 * bayes_cover:.0f}%")
bins = np.linspace(min(est.min(), post_mean.min()) - 0.1,
max(est.max(), post_mean.max()) + 0.1, 41)
plt.hist(est, bins, color="#2166ac", alpha=0.5, label="Data only")
plt.hist(post_mean, bins, color="#d6604d", alpha=0.6,
label="Bayesian posterior mean")
plt.axvline(truth, color="black", linewidth=2)
plt.axvline(prior_off, color="#d6604d", linestyle="--")
plt.xlabel("Estimate")
plt.ylabel("Replications")
plt.legend()
plt.show()Key takeaways
- Bayesian methods are tools. Using them by reflex, as an identity, is how they get misused.
- A Bayesian answer is only as good as its prior. Check the prior against the data and against outside knowledge.
- Good priors make Bayesian inference shine. Bad, confident priors make it worse than having none.
Source
- Andrew Gelman, Bayes, Bayesians (2008).