Skip to content
svgnoninferiority-forest

Non-inferiority to the champion

Is the candidate no worse than the champion by more than the margin we accept?

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

How to read it

  1. Each row is one metric: the dot is candidate minus champion, the bar its 95% paired interval.
  2. Right favours the candidate on every row; a lower-is-better metric is flipped first.
  3. The dashed line is the margin. The gate passes when the whole bar stays to its right.
  1. Callout 1: The whole interval clears the margin: non-inferior.
  2. Callout 2: Dashed line: the largest loss you accept.
  3. Callout 3: This interval reaches past the margin, so the gate holds.

Watch out

  • Passing means no worse than the margin, not better than the champion: read the dot and the zero line for that.
  • Widening the margin after a failure defeats the gate; choose it before you look.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the host's numbers as given; the chart computes nothing statistical.
  • Differences are oriented so right favours the candidate; a lower-is-better metric such as RMSE is flipped first.
  • Two-sided 95% paired bootstrap on the same held-out rows (2,000 resamples of rows on the shared generator), which is a one-sided 97.5% non-inferiority test at the margin.
# Non-inferiority to the champion — Codesplash Chart Lab (recipe "noninferiority-forest")
# 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("noninferiority-forest-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

L = "metric"
E = "difference"
LO = "low"
HI = "high"
MG = "margin"
d = df.dropna(subset=[E, LO, HI, MG]).reset_index(drop=True)
fig, ax = plt.subplots(figsize=(8, max(2.5, 0.7 * len(d) + 1)))
ax.axvline(0, color="#888888", linewidth=1)
for i, row in d.iterrows():
    color = "#2e8b57" if row[LO] > -row[MG] else "#c0392b"
    ax.plot([-row[MG], -row[MG]], [i - 0.4, i + 0.4], color="#c0392b", linestyle="--", linewidth=1)
    ax.plot([row[LO], row[HI]], [i, i], color=color, linewidth=2)
    ax.plot(row[E], i, "o", color=color)
ax.set_yticks(range(len(d)), d[L].astype(str))
ax.invert_yaxis()
ax.set_xlabel("candidate minus champion (right = candidate better)")
plt.show()

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