Skip to main content

P-values and U-values

Noise and evidence
Principle or heuristic
Advanced
They’re different.
Published

November 9, 2026

Modified

November 13, 2026

Entry #8 in Andrew Gelman’s Handy Statistical Lexicon. Original discussion: I hate the so-called Fisher exact test: a pointer to one of my favorite articles.

Filed under Noise and evidence · Principle or heuristic · Advanced.

Related terms: posterior predictive p-value, calibration, uniform p-values.

Source check: ✓ The explanation was checked against the source. Checked against the post, which points to Gelman (2003) for the definitions.

What it is

A p-value is a probability: the chance, under some model, of seeing a test statistic as or more extreme than the observed one. A u-value is any statistic that has a uniform(0, 1) distribution when the model is true. Gelman’s point is that the two are different things. Classical p-values for simple continuous tests happen to be u-values. Many perfectly sensible p-values are not, and posterior predictive p-values are the leading example.

The post itself, titled “I hate the so-called Fisher exact test”, is a pointer to one of Gelman’s favorite articles, “A Bayesian formulation of exploratory data analysis and goodness-of-fit testing” (International Statistical Review, 2003). That article has what he calls “the first published definition (I think) of U-values and P-values” (section 2.3), and section 3.3 makes his argument against the Fisher exact test in detail.

Why it matters

People calibrate their reactions to p-values by assuming uniformity: under the null, p < 0.05 happens 5% of the time. That works for u-values. A posterior predictive p-value, used to check a Bayesian model, is typically concentrated near 0.5 when the model is true, because the same data are used to fit the model and to check it. Treating it as uniform gives the wrong impression of how surprising a result is. Conversely, a non-uniform p-value is not “broken.” It is still a valid probability statement about the replicated data.

How it works

For a test statistic \(T\):

  • Classical p-value: \(p = \Pr(T(y^{\text{rep}}) \ge T(y) \mid \theta_0)\). If \(\theta_0\) is fixed and \(T\) is continuous, \(p \sim \mathrm{U}(0, 1)\) under the null, so it is a u-value.
  • Posterior predictive p-value: \(p_B = \Pr(T(y^{\text{rep}}) \ge T(y) \mid y)\), which averages over the posterior for \(\theta\). Because the posterior is centered near the data, \(y^{\text{rep}}\) resembles \(y\). The resulting p-values pile up near 0.5. For a statistic the model fits directly, such as the sample mean, they can be exactly 0.5 every time.

Simulated example

We generate 1,000 datasets from a normal model with known variance and compute two checks on each. One is a classical z-test p-value at the true mean. The other is a posterior predictive p-value under a vague prior, for a chosen test statistic. The model is true in every dataset.

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, pnorm, fmt, debounce} from "../js/stats.js"

viewof stat = debounce(Inputs.radio(["Sample mean", "Sample maximum", "Sample variance"], {value: "Sample maximum", label: "Test statistic T(y)"}))
viewof n = debounce(Inputs.range([5, 100], {value: 20, step: 5, label: "Observations per dataset"}))
viewof seed = debounce(Inputs.range([1, 500], {value: 12, step: 1, label: "Random seed"}))

pvals = {
  const r = rng(seed);
  const T = y => stat === "Sample mean" ? mean(y) : stat === "Sample maximum" ? Math.max(...y) : mean(y.map(v => (v - mean(y)) ** 2));
  return range(1000).map(k => {
    const theta = 0;
    const y = r.normals(n, theta, 1), ybar = mean(y);
    const classical = 1 - pnorm((ybar - theta) * Math.sqrt(n));
    const tObs = T(y);
    let exceed = 0;
    for (let s = 0; s < 200; s++) {
      const th = r.normal(ybar, 1 / Math.sqrt(n));     // posterior under flat prior
      if (T(r.normals(n, th, 1)) >= tObs) exceed++;
    }
    return {k, classical, ppp: exceed / 200};
  });
}
pLong = pvals.flatMap(d => [{type: "Classical p-value (a u-value)", p: d.classical}, {type: "Posterior predictive p-value", p: d.ppp}])

Plot.plot({
  ariaLabel: "P-values and U-values: simulation chart",
  ariaDescription: "Horizontal axis: p. Vertical axis: Datasets. The chart updates with the controls above it, and the summary below the charts states the result in words.",
  height: 300,
  facet: {data: pLong, y: "type", marginRight: 190},
  x: {label: "p", domain: [0, 1]},
  y: {label: "Datasets", grid: true},
  marks: [
    Plot.rectY(pLong, Plot.binX({y: "count"}, {x: "p", fill: "type", thresholds: 20, domain: [0, 1]})),
    Plot.ruleY([1000 / 20], {stroke: "currentColor", strokeDasharray: "4 3"}),
    Plot.ruleY([0])
  ],
  color: {range: ["#2166ac", "#d6604d"]}
})
# P-values and U-values: posterior predictive p-values are not uniform.
1stat <- "Sample maximum" # or "Sample mean", "Sample variance"
n <- 20 # observations per dataset
2set.seed(12)

T_stat <- switch(stat,
  "Sample mean" = mean,
  "Sample maximum" = max,
  "Sample variance" = function(y) mean((y - mean(y))^2)
)
res <- t(replicate(1000, {
  y <- rnorm(n, 0, 1)
  ybar <- mean(y) # data from the true model
3  classical <- 1 - pnorm(ybar * sqrt(n)) # a u-value: uniform
4  th <- rnorm(200, ybar, 1 / sqrt(n)) # posterior, flat prior
  yrep <- matrix(rnorm(200 * n, th, 1), 200) # replicated datasets
5  ppp <- mean(apply(yrep, 1, T_stat) >= T_stat(y))
  c(classical = classical, ppp = ppp)
}))
extreme <- colMeans(res < 0.05 | res > 0.95)
cat("Share of p-values below 0.05 or above 0.95 (uniform: 10%):\n",
  "classical ", round(100 * extreme[1]), "%, posterior predictive ",
  round(100 * extreme[2]), "%\n",
  sep = ""
)

6par(mfrow = c(1, 2))
hist(res[, 1],
  breaks = 20, col = "grey70", border = "white",
  main = "Classical p-value", xlab = "p"
)
hist(res[, 2],
  breaks = 20, col = "#2166ac", border = "white",
  main = "Posterior predictive p-value", xlab = "p"
)
1
The page’s controls: the test statistic and the observations per dataset.
2
Fixes the random numbers so the run is reproducible.
3
A classical p-value, computed from the sampling distribution of the mean. Under the true model it is uniform: a u-value.
4
Draws from the posterior, with a flat prior.
5
The posterior predictive p-value: how often a replicated dataset’s statistic exceeds the observed one. It need not be uniform.
6
The two histograms. The classical one is flat; the posterior predictive one piles up in the middle, because the data were used twice.
# P-values and U-values: posterior predictive p-values are not uniform.
from statistics import NormalDist
import numpy as np
import matplotlib.pyplot as plt

stat = "Sample maximum"  # or "Sample mean", "Sample variance"
n = 20                   # observations per dataset
rng = np.random.default_rng(12)

T = {"Sample mean": lambda y: y.mean(axis=-1),
     "Sample maximum": lambda y: y.max(axis=-1),
     "Sample variance": lambda y: y.var(axis=-1)}[stat]
y = rng.normal(0, 1, (1000, n))  # 1000 datasets from the true model
ybar = y.mean(axis=1)
classical = 1 - np.array([NormalDist().cdf(v) for v in ybar * np.sqrt(n)])
th = rng.normal(ybar[:, None], 1 / np.sqrt(n), (1000, 200))  # posterior
yrep = rng.normal(th[:, :, None], 1, (1000, 200, n))  # replicated datasets
ppp = np.mean(T(yrep) >= T(y)[:, None], axis=1)


def extreme(p):
    return 100 * np.mean((p < 0.05) | (p > 0.95))


print("Share of p-values below 0.05 or above 0.95 (uniform: 10%):")
print(f"classical {extreme(classical):.0f}%, posterior predictive "
      f"{extreme(ppp):.0f}%")

fig, ax = plt.subplots(1, 2, sharey=True)
ax[0].hist(classical, bins=20, color="0.7")
ax[0].set_title("Classical p-value")
ax[1].hist(ppp, bins=20, color="#2166ac")
ax[1].set_title("Posterior predictive p-value")
plt.show()

Key takeaways

  • A p-value is a probability. A u-value is a statistic that is uniform under the model. Classical tests blur the two.
  • Posterior predictive p-values are usually not uniform. Extreme values are rarer than the nominal level suggests, so an extreme one is especially telling.
  • Interpret a p-value by asking what it is a probability of, not by assuming uniformity.

Source

Back to top