Skip to content
svgbf-models

Model Bayes factors

Which model of the factors do the data support, and by how much?

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

How to read it

  1. Read each bar as how much more the data support that model than the intercept-only model.
  2. Longest bar: the best-supported model.
  3. Read the posterior probability to weigh models against each other.
  1. Callout 1: The best-supported model.
  2. Callout 2: Its Bayes factor and posterior probability.
  3. Callout 3: BF = 1: no better than the baseline.

Watch out

  • Posterior probabilities depend on equal prior odds across these models and on which models are listed.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Bars start at BF = 1 (no evidence); the strongest model is drawn solid. Percentages are posterior model probabilities with equal prior odds over the models shown and the intercept-only model.
# Model Bayes factors — Codesplash Chart Lab (recipe "bf-models")
# controls: defaults
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("bf-models-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

M = "model"
B = "BF"
PP = "posterior"
def df_models():
    d = df.dropna(subset=[M, B])
    d = d[d[B] > 0].sort_values(B, ascending=False)
    return pd.DataFrame({"model": d[M].astype(str), "bf": d[B], "posterior": d[PP] if PP else np.nan})
d = df_models()
fig, ax = plt.subplots(figsize=(7, 0.5 * len(d) + 1.2))
y = np.arange(len(d))[::-1]
ax.barh(y, d["bf"], left=1, color=PALETTE[0], alpha=0.7)
ax.set_xscale("log")
ax.set_yticks(y, d["model"])
ax.axvline(1, color="grey", linewidth=0.8)
for i, (bf, pp) in zip(y, zip(d["bf"], d["posterior"])):
    ax.text(1 + bf, i, f" {bf:.3g}" + (f" · {pp:.0%}" if pd.notna(pp) else ""), va="center", fontsize=8)
ax.set_xlabel("Bayes factor against the intercept-only model (log scale)")
plt.show()

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