Skip to content
svgprior-posterior

Prior and posterior

How did the data move belief about the effect, and how much more (or less) plausible is the null value now?

Demo data · seed 20261101 · 322 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Compare the dashed prior with the solid posterior: the data moved belief from one to the other.
  2. Compare heights at the test value: if the posterior is lower there, the data favour an effect.
  3. Read the shaded credible interval: where the effect probably lies, given the prior.
  1. Callout 1: The prior's height at the test value.
  2. Callout 2: The posterior's height at the test value.
  3. Callout 3: The posterior: belief about the effect after the data.

Watch out

  • The result depends on the prior. Check robustness across prior widths.

Defaults

Test value (H₀)
0
The effect value to test, usually 0; the chart compares prior and posterior there.
Range -1,000,000,000 to 1,000,000,000, step 0.01
Credible interval lower (equal bounds = none)
0
The lower bound of the credible interval to shade.
Range -1,000,000,000 to 1,000,000,000, step 0.001
Credible interval upper
0
The upper bound of the credible interval to shade.
Range -1,000,000,000 to 1,000,000,000, step 0.001
Credible level
0.95
The share of posterior probability inside the interval.
Range 0.5 to 0.999, step 0.01
Bayes factor BF₁₀ to label (0 = none)
0
Print this Bayes factor on the chart.
Range 0 to 1,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000, step 0.01

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Prior dashed, posterior filled; the dots mark both heights at the test value. For a point null nested in the alternative, posterior height ÷ prior height = BF₀₁ (Savage–Dickey density ratio), the engines' identity check.
  • The credible interval is the engine's equal-tailed interval (quantiles of the posterior).
# Prior and posterior — Codesplash Chart Lab (recipe "prior-posterior")
# controls: point=0, ci_low=0, ci_high=0, cred=0.95, bf10=0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("prior-posterior-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["curve"] = pd.Categorical(df["curve"].astype("string"), categories=["Prior", "Posterior"])

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
X = "δ (standardized effect)"
D = "density"
K = "curve"
POINT = 0  # the test value
is_prior = df[K].astype(str).str.contains("prior", case=False)
prior, post = df[is_prior].sort_values(X), df[~is_prior].sort_values(X)
fig, ax = plt.subplots(figsize=(7, 4.5))

ax.plot(prior[X], prior[D], color=REF, linestyle="--", label="prior")
ax.plot(post[X], post[D], color=PALETTE[0], linewidth=2, label="posterior")
ax.axvline(POINT, color=REF, linewidth=0.8, linestyle=":")
ax.scatter([POINT], [np.interp(POINT, prior[X], prior[D])], s=30, facecolor="white", edgecolor=REF, zorder=3)
ax.scatter([POINT], [np.interp(POINT, post[X], post[D])], s=30, color=PALETTE[0], zorder=3)
ax.set_xlabel(X)
ax.set_ylabel("density")
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads prior-posterior-demo.csv · app theme from the optional codesplash helper