svgnoninferiority-forest
Non-inferiority to the champion
Is the candidate no worse than the champion by more than the margin we accept?
How to read it
- Each row is one metric: the dot is candidate minus champion, the bar its 95% paired interval.
- Right favours the candidate on every row; a lower-is-better metric is flipped first.
- The dashed line is the margin. The gate passes when the whole bar stays to its right.
- Callout 1: The whole interval clears the margin: non-inferior.
- Callout 2: Dashed line: the largest loss you accept.
- 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
# Non-inferiority to the champion — Codesplash Chart Lab (recipe "noninferiority-forest")
# controls: defaults
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
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 px.colors.qualitative.Plotly
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 = go.Figure()
for _, row in d.iterrows():
color = "#2e8b57" if row[LO] > -row[MG] else "#c0392b"
fig.add_scatter(x=[row[E]], y=[str(row[L])], mode="markers", marker=dict(color=color, size=9), showlegend=False,
error_x=dict(type="data", symmetric=False, array=[row[HI] - row[E]], arrayminus=[row[E] - row[LO]], color=color))
fig.add_scatter(x=[-row[MG], -row[MG]], y=[str(row[L]), str(row[L])], mode="markers", marker=dict(symbol="line-ns-open", size=22, color="#c0392b"), showlegend=False)
fig.add_vline(x=0, line_color="#888888")
fig.update_layout(xaxis_title="candidate minus champion (right = candidate better)", template="plotly_white")
fig.show()Needs pandas, numpy, plotly · reads noninferiority-forest-demo.csv · app theme from the optional codesplash helper
# Non-inferiority to the champion — Codesplash Chart Lab (recipe "noninferiority-forest")
# controls: defaults
library(ggplot2)
has_cs <- isTRUE(requireNamespace("codesplashr", quietly = TRUE)) # optional: the app's chart theme
theme_cs <- if (has_cs) codesplashr::theme_codesplash(dark = FALSE) else theme_minimal()
cs_cat <- if (has_cs) codesplashr::cs_palette(dark = FALSE)$categorical else grDevices::palette.colors(8, "Okabe-Ito")
if (has_cs) update_geom_defaults("text", list(colour = codesplashr::cs_palette(dark = FALSE)$foreground))
df <- read.csv("noninferiority-forest-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["metric"]] <- factor(df[["metric"]])
L <- "metric"
E <- "difference"
LO <- "low"
HI <- "high"
MG <- "margin"
d <- df[stats::complete.cases(df[c(E, LO, HI, MG)]), ]
d$.pass <- d[[LO]] > -d[[MG]]
p <- ggplot(d, aes(y = reorder(.data[[L]], -seq_along(.data[[L]])), x = .data[[E]], colour = .pass)) +
geom_vline(xintercept = 0, colour = "#888888") +
geom_errorbar(aes(xmin = .data[[LO]], xmax = .data[[HI]]), width = 0, orientation = "y", linewidth = 0.8) +
geom_point(size = 2.5) +
geom_point(aes(x = -.data[[MG]]), shape = 124, size = 7, colour = "#c0392b") +
scale_colour_manual(values = c("TRUE" = "#2e8b57", "FALSE" = "#c0392b"), guide = "none") +
labs(x = "candidate minus champion (right = candidate better)", y = NULL) +
theme_minimal()
print(p)Needs ggplot2 · reads noninferiority-forest-demo.csv · app theme from the optional codesplashr helper