Fix the data. Vary θ.
Compare all three tail conventions
| Quantity | Observed bar counted | Probability |
|---|
“Strict tail” is included to explain the algebra; it is not the usual valid exact p-value. A mid-p value also lacks the usual conservative Type I error guarantee.
The connection is algebra—not a reversal of conditioning.
The sampling probability and the posterior probability answer different questions. Here is why their numerical values are linked in this particular model.
Data turn a flat prior into a beta posterior.
With k successes in n independent trials, the likelihood is proportional to θk(1−θ)n−k. Multiplication by a uniform prior leaves this shape unchanged.
The posterior tail on the side opposite the alternative is an area over parameter values. The p-value is instead a sum over possible data.
Beta–binomial relation: NIST DLMF, §8.17, equations 8.17.1–5.
At θ₀ = ½, that area equals the mid-p.
For either prespecified direction, a beta–binomial identity gives the following exact relationship under the uniform prior:
The ordinary p-value counts the whole observed bar. The posterior tail corresponds to counting half. No approximation is involved in this identity.
Place n+1 independent uniform random points on [0, 1], then mark the (k+1)-th smallest. This marked point has a Beta(k+1, n−k+1) distribution—the same distribution as the uniform-prior posterior. Count how many points fall below ½, and compare that count with the marked point’s position.
This is a mathematical construction, not an extra observation. It always illustrates the uniform prior, even when another prior is selected in the explorer.
Why does this leave exactly half of the observed bar?
Write the number of points below ½ as Y = B + C, with B ∼ Binomial(n, ½) for the first n points, and an independent C ∼ Bernoulli(½) for the extra point.
For the upper-tailed alternative, the marked point is below ½ exactly when Y ≥ k+1. If B > k, the event already occurs. If B = k, it occurs only when the extra point is below ½—a probability of one half. If B < k, it cannot occur.
For the lower-tailed alternative, the marked point is above ½ exactly when Y ≤ k. This gives Pr(B < k) + ½ Pr(B = k). In either direction, we obtain the mid-p value.
The rank distribution follows because the density of the r-th smallest of m uniform points is proportional to tr−1(1−t)m−r. Taking r=k+1 and m=n+1 yields the required beta density.
Mathematics & teaching notes
Assumptions, exact identities, and a suggested classroom sequence. All calculations use θ₀ = ½. Let δ = θ − ½ denote the signed effect.
Keep the test direction fixed.
The model is X | θ ∼ Binomial(n, θ), with n independent Bernoulli trials, a common success probability θ, and a fixed sample size. The Bayesian model uses θ ∼ Beta(a,b), giving θ | k,n ∼ Beta(k+a,n−k+b).
| Prespecified alternative | Usual one-sided p-value | Corresponding posterior tail q |
|---|---|---|
| θ > ½, or δ > 0 | Pr(X ≥ k | θ = ½) | Pr(θ < ½ | k,n), or Pr(δ < 0 | k,n) |
| θ < ½, or δ < 0 | Pr(X ≤ k | θ = ½) | Pr(θ > ½ | k,n), or Pr(δ > 0 | k,n) |
“Opposite to the observed effect” is appropriate only when the sample effect k/n − ½ agrees with the prespecified alternative. When it points the other way, q is the posterior mass on the same side as the sample effect. At k/n=½, the observed effect has no sign.
Choosing whichever one-sided p-value is smaller after seeing the data is not a prespecified one-sided test. This app never changes the direction automatically.
The incomplete beta identity
Write It(a,b) for the cumulative probability up to t under Beta(a,b). For positive integer m ≤ N,
Thus, for the upper-tailed test, pexact=I½(k,n−k+1) for k ≥ 1. With a uniform prior,
The lower-tailed result follows by complementing the corresponding n+1-trial probability. The uniform-prior mid-p identity holds for every 0 ≤ k ≤ n, including k = 0 and k = n.
NIST DLMF, §8.17, especially 8.17.5 and the symmetry identity 8.17.4. The half-bar formula is obtained by conditioning on the final Bernoulli trial.
What changes if θ₀ is not ½?
Under a uniform prior, the upper-tail posterior probability is
For the lower-tailed alternative,
Only at θ₀ = ½ do both become the ordinary mid-p convention. The interface intentionally fixes θ₀ at ½.
Can the posterior equal the ordinary p-value exactly?
Yes, with particular improper directional priors. They are included in the prior menu as advanced demonstrations, not as default recommendations.
| Fixed prior kernel | Posterior | Exact match | When proper? |
|---|---|---|---|
| π(θ) ∝ 1/θ Formal Beta(0,1) | Beta(k,n−k+1) | Pr(θ < ½ | k,n) = upper exact p | k > 0 |
| π(θ) ∝ 1/(1−θ) Formal Beta(1,0) | Beta(k+1,n−k) | Pr(θ > ½ | k,n) = lower exact p | k < n |
Neither prior integrates to a finite constant. Consequently, neither is an ordinary beta probability distribution, and neither is plotted as a normalized prior. If the posterior is also improper, the app displays “undefined” rather than reporting a probability. These matches are direction-specific; changing the test direction does not silently change the prior.
These improper priors are sufficient for the stated posterior-tail identities when the posterior is proper. They do not supply arbitrary Bayes-factor comparisons with well-defined prior normalizing constants.
Discreteness, prior information, and interpretation
Discreteness. With the uniform prior, the ordinary p-value exceeds q by exactly half of the observed outcome’s null probability. This difference can be appreciable with small samples. For n = 10 and k = 8 in the upper direction,
The largest absolute gap for a given n is
It decreases as n grows. However, a small absolute gap need not be a small relative gap when both tails are tiny. The larger-sample classroom example keeps the standardized distance from the null roughly constant, rather than keeping the observed proportion fixed.
Prior information. Changing the prior changes the posterior but not the p-value. The uniform-prior identity does not extend to arbitrary beta priors. With increasing information from the data, a smooth fixed prior can have less influence near the likelihood’s peak, but this is not a finite-sample equality.
Mid-p calibration. A mid-p is a modified tail probability, not the ordinary conservative exact p-value. In the n = 10 upper-tailed test, rejecting when mid-p ≤ 0.05 means rejecting for X ≥ 8; under θ = ½, this happens with probability 0.0546875, which exceeds 0.05.
A tail is not a point null. The continuous posterior assigns zero probability to the singleton θ = ½ by construction. Its mass below or above ½ is not the posterior probability of the point null, and neither p nor q is itself a Bayes factor. Adding a point mass at ½ changes the Bayesian model and its interpretation.
From two pictures to one identity
- Begin with 8 successes in 10 trials. Keep the uniform prior and the upper-tailed alternative. Hide answers. Ask which quantities vary in the left and right panels, and which tail is relevant.
- Reveal the numbers. The ordinary p-value is about 0.0547; the posterior probability of θ < ½ is about 0.0327. Ask where the difference could come from.
- Switch to “Half: mid-p.” Half of the orange observed bar is excluded. The probabilities now agree exactly. The posterior has not changed.
- Open “Why the equality?” Show a boundary-count example and reflect the extra point. When the first n points have exactly k values below ½, only one of the two extra-point sides makes the event occur.
- Change only the prior. Use the concentrated Beta(50,50) example to break the match without changing the data or p-value. Then return to the uniform prior and try larger samples.
- Reverse the direction. Retain k > n/2 and select θ < ½. Both the selected mid-p and the uniform-prior posterior tail exceed one half; the tail now agrees with the observed sign, but opposes the prespecified alternative.
Further reading
NIST Digital Library of Mathematical Functions. §8.17: Incomplete Beta Functions, especially equations 8.17.1–5 and 8.17.22–23. Definitions, beta–binomial identity, and continued fractions. This supplies the exact mathematical identity used here; the half-bar and extra-point explanations are derived in the app.
Marsman, M., & Wagenmakers, E.-J. (2017). Three insights from a Bayesian interpretation of the one-sided P value. Educational and Psychological Measurement, 77(3), 529–539. doi:10.1177/0013164416669201. Background on posterior-tail interpretations of one-sided p-values; the app does not assume that the general continuous-model equality automatically holds for a discrete binomial test.
Computation. Binomial probabilities are computed by a mode-centered recurrence and normalization. Posterior tails are computed independently with the regularized incomplete beta function, using log-gamma calculations and a continued fraction; the beta symmetry identity is used to evaluate the required tail directly. Display curves are not used to compute probabilities. Curves with infinite endpoint density are clipped visually and labeled. Extremely small values may be rounded or underflow at floating-point limits.
Simulation. The rank illustration uses a fixed-seed pseudorandom generator for reproducibility. “Simulate 2,000 sets” uses unrestricted independent draws. Boundary-count examples are deliberately conditioned illustrations and never enter the simulation estimates. Reflecting the extra point is an illustration, not an additional simulation run.
Use. This is a self-contained HTML file: no installation, account, network connection, tracking, or external libraries are required. “Save this view” creates another standalone file with your chosen settings; SVG plots can be inserted into teaching slides. References open external sites only when clicked.