Skip to main content

Weakly Informative Priors

Building and checking models
Method or technique
Advanced
What you should be doing when you think you want to use noninformative priors.
Published

November 9, 2026

Modified

November 13, 2026

Entry #7 in Andrew Gelman’s Handy Statistical Lexicon. Original discussion: How to set tuning parameters.

Filed under Building and checking models · Method or technique · Advanced.

Related terms: default prior, separation in logistic regression, regularization, Cauchy prior.

Source check: ✓ The explanation was checked against the source. The source post is the abstract of Gelman’s talk on bayesglm.

What it is

A weakly informative prior deliberately carries less information than you actually have, but enough to rule out values that are absurd. It is not “uninformative”: it encodes the scale of the problem. A typical example is a \(\mathrm{Normal}(0, 2.5)\) or \(\mathrm{Cauchy}(0, 2.5)\) prior on a logistic regression coefficient for a standardized predictor. That says an effect of 50 on the log-odds scale is essentially impossible, but takes no strong position on whether the effect is 0.2 or 1.5.

Why it matters

“Noninformative” flat priors look objective, but they assign as much prior mass to absurd values as to plausible ones. With sparse data or separation, that produces infinite or wildly unstable estimates. It also produces improper posteriors in hierarchical models and samplers that won’t converge. A weakly informative prior regularizes estimates where the data are weak and gets out of the way where the data are strong.

How it works

With a normal prior \(\beta \sim \mathrm{N}(0, s^2)\), the posterior mode maximizes

\[ \log p(y \mid \beta) - \frac{\beta^2}{2 s^2}. \]

When the likelihood is flat in some direction, as under complete separation in logistic regression where the MLE is \(\pm\infty\), the penalty term keeps the estimate finite. When the likelihood is sharply peaked, the penalty barely moves it. The scale \(s\) should reflect what a large but plausible effect looks like in your units.

Simulated example

We repeat a small logistic-regression study 200 times. In each, the slope is estimated with a flat prior, which gives essentially the maximum likelihood estimate, and by posterior mode under a \(\mathrm{N}(0, s)\) prior. Both fits give the intercept a very weak \(\mathrm{N}(0, 10)\) prior. With small samples, some datasets are perfectly separated and the MLE runs off toward infinity.

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, mean, invLogit, fmt, pct, median} from "../js/stats.js"

viewof n = Inputs.range([10, 200], {value: 20, step: 5, label: "Observations per study"})
viewof trueBeta = Inputs.range([0, 3], {value: 1.5, step: 0.1, label: "True slope β"})
viewof priorSd = Inputs.range([0.5, 10], {value: 2.5, step: 0.5, label: "Prior sd s"})
viewof seed = Inputs.range([1, 500], {value: 13, step: 1, label: "Random seed"})

fitLogit = (x, y, sSlope) => {
  // Newton–Raphson for the posterior mode of (alpha, beta); intercept prior sd 10.
  let a = 0, b = 0;
  const pa = 1 / 100, pb = sSlope ? 1 / (sSlope * sSlope) : 0;
  for (let it = 0; it < 60; it++) {
    let ga = -pa * a, gb = -pb * b, haa = -pa, hab = 0, hbb = -pb;
    for (let i = 0; i < x.length; i++) {
      const p = invLogit(a + b * x[i]), w = p * (1 - p);
      ga += y[i] - p; gb += (y[i] - p) * x[i];
      haa -= w; hab -= w * x[i]; hbb -= w * x[i] * x[i];
    }
    const det = haa * hbb - hab * hab;
    if (!Number.isFinite(det) || Math.abs(det) < 1e-12) { b += Math.sign(gb) * 5; continue; }
    a -= (hbb * ga - hab * gb) / det;
    b -= (haa * gb - hab * ga) / det;
    if (Math.abs(b) > 1e3) break;
  }
  return Math.max(-50, Math.min(50, b));
}

studies = {
  const r = rng(seed);
  return range(200).flatMap(k => {
    const x = r.normals(n), y = x.map(v => r.bernoulli(invLogit(-0.3 + trueBeta * v)));
    return [
      {k, method: "Flat prior on slope (≈ MLE)", est: fitLogit(x, y, 0)},
      {k, method: `Weakly informative N(0, ${priorSd})`, est: fitLogit(x, y, priorSd)}
    ];
  });
}

Plot.plot({
  ariaLabel: "Weakly Informative Priors: simulation chart",
  ariaDescription: "Horizontal axis: Estimated slope (capped at ±50). Vertical axis: Studies. The chart updates with the controls above it, and the summary below the charts states the result in words.",
  height: 300,
  facet: {data: studies, y: "method", marginRight: 150},
  x: {label: "Estimated slope (capped at ±50)", type: "symlog", domain: [-50, 50]},
  y: {label: "Studies", grid: true},
  marks: [
    Plot.rectY(studies, Plot.binX({y: "count"}, {x: "est", fill: "method", thresholds: 60})),
    Plot.ruleX([trueBeta], {stroke: "currentColor", strokeWidth: 2}),
    Plot.ruleY([0])
  ],
  color: {range: ["#d6604d", "#2166ac"]}
})
# Weakly Informative Priors: logistic regression with small samples.
1n <- 20 # observations per study
true_beta <- 1.5 # true slope
prior_sd <- 2.5 # prior sd on the slope
2set.seed(14)

# Posterior mode by Newton-Raphson; intercept prior sd 10, slope prior sd s
# (s = 0 means a flat prior, which gives the maximum likelihood estimate)
3fit_logit <- function(x, y, s) {
  prec <- c(1 / 100, if (s > 0) 1 / s^2 else 0)
  beta <- c(0, 0)
  X <- cbind(1, x)
  for (it in 1:60) {
    p <- plogis(X %*% beta)
    grad <- t(X) %*% (y - p) - prec * beta
    H <- -t(X) %*% (X * as.vector(p * (1 - p))) - diag(prec)
    step <- tryCatch(solve(H, grad), error = function(e) NULL)
    if (is.null(step)) {
      beta[2] <- beta[2] + sign(grad[2]) * 5
      next
    }
    beta <- beta - as.vector(step)
    if (abs(beta[2]) > 1e3) break
  }
  max(-50, min(50, beta[2]))
}
est <- t(replicate(200, {
  x <- rnorm(n)
  y <- rbinom(n, 1, plogis(-0.3 + true_beta * x))
4  c(flat = fit_logit(x, y, 0), weak = fit_logit(x, y, prior_sd))
}))
5rmse <- sqrt(colMeans((est - true_beta)^2))
cat("Flat prior: ", round(100 * mean(abs(est[, 1]) > 20)), "% of ",
  "estimates blow up past +/-20; RMSE ", round(rmse[1], 2), "\n",
  "Weakly informative N(0, ", prior_sd, "): RMSE ", round(rmse[2], 2),
  "\n",
  sep = ""
)

6boxplot(pmin(pmax(est, -10), 10),
  col = c("grey70", "#2166ac"),
  names = c("Flat prior (MLE)", "Weakly informative"),
  ylab = "Estimated slope (clipped at +/-10)"
)
abline(h = true_beta, lty = 2)
1
The page’s controls: observations per study, the true slope and the prior standard deviation on the slope.
2
Fixes the random numbers so the run is reproducible.
3
A logistic regression fitted by Newton-Raphson to the posterior mode. A prior sd of zero means a flat prior, which gives maximum likelihood.
4
Each of 200 small studies fitted both ways.
5
Root-mean-square error of each estimator against the truth.
6
The two sets of estimates, clipped for display. Under a flat prior, separated datasets send the slope toward infinity; the weakly informative prior keeps it finite without pulling it far.
# Weakly Informative Priors: logistic regression with small samples.
import numpy as np
import matplotlib.pyplot as plt

n = 20           # observations per study
true_beta = 1.5  # true slope
prior_sd = 2.5   # prior sd on the slope
rng = np.random.default_rng(13)


def fit_logit(x, y, s):
    # Posterior mode by Newton-Raphson; intercept prior sd 10, slope prior
    # sd s (s = 0 means a flat prior: the maximum likelihood estimate)
    prec = np.array([1 / 100, 1 / s ** 2 if s > 0 else 0])
    beta, X = np.zeros(2), np.column_stack([np.ones(len(x)), x])
    for _ in range(60):
        p = 1 / (1 + np.exp(-X @ beta))
        grad = X.T @ (y - p) - prec * beta
        H = -(X.T * (p * (1 - p))) @ X - np.diag(prec)
        if abs(np.linalg.det(H)) < 1e-12:
            beta[1] += np.sign(grad[1]) * 5
            continue
        beta -= np.linalg.solve(H, grad)
        if abs(beta[1]) > 1e3:
            break
    return np.clip(beta[1], -50, 50)


flat, weak = [], []
for _ in range(200):
    x = rng.normal(size=n)
    y = rng.binomial(1, 1 / (1 + np.exp(-(-0.3 + true_beta * x))))
    flat.append(fit_logit(x, y, 0))
    weak.append(fit_logit(x, y, prior_sd))
flat, weak = np.array(flat), np.array(weak)


def rmse(v):
    return np.sqrt(np.mean((v - true_beta) ** 2))


print(f"Flat prior: {100 * np.mean(np.abs(flat) > 20):.0f}% of estimates "
      f"blow up past +/-20; RMSE {rmse(flat):.2f}")
print(f"Weakly informative N(0, {prior_sd}): RMSE {rmse(weak):.2f}")

plt.boxplot([np.clip(flat, -10, 10), np.clip(weak, -10, 10)])
plt.xticks([1, 2], ["Flat prior (MLE)", "Weakly informative"])
plt.axhline(true_beta, color="black", linestyle="--")
plt.ylabel("Estimated slope (clipped at +/-10)")
plt.show()

Key takeaways

  • No prior is truly noninformative. Flat priors assign belief to absurd values.
  • Weakly informative priors encode the scale of the problem and give stable estimates for little cost.
  • They matter most when data are sparse and hardly at all when data are plentiful.

Source

Back to top