svgsequential-boundary
Group-sequential boundaries
At each interim look, has the test statistic crossed the efficacy or futility boundary?
How to read it
- Read the black path as the test statistic at each look.
- Crossing the upper boundary means stop for efficacy; the lower, for futility.
- Boundaries are wider early because evidence is thin.
- Callout 1: The path crosses the efficacy boundary here.
- Callout 2: Efficacy region.
- Callout 3: Futility region.
Watch out
- Estimates at early stopping tend to be too large: use the adjusted estimate.
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.
- Series named like efficacy/upper/lower are boundaries (a level holding both signs is split into upper and lower for two-sided designs); futility is dashed; the observed path is drawn on top.
- A crossing is the first observed look with z at or above the efficacy boundary interpolated at that information; the engine's spending function and decision are authoritative.
# Group-sequential boundaries — Codesplash Chart Lab (recipe "sequential-boundary")
# 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("sequential-boundary-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["series"] = pd.Categorical(df["series"].astype("string"), categories=["efficacy (O'Brien–Fleming)", "futility (non-binding)", "observed z"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
I = "information fraction"
Z = "z statistic"
B = "series"
groups = levels_of(df[B]) if B else [None]
series = []
for name in groups:
d = df if name is None else df[df[B].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[I]).sort_values(I)))
fig, ax = plt.subplots(figsize=(8, 4.5))
ax.axhline(0, color="grey", linewidth=0.8)
for name, d in series:
low = str(name).lower()
kind = "futility" if "futil" in low else "observed" if any(w in low for w in ("observ", "path", "stat")) else "efficacy"
col = {"efficacy": PALETTE[0], "futility": PALETTE[1], "observed": "black"}[kind]
for part in ([d[d[Z] >= 0], d[d[Z] < 0]] if kind != "observed" and (d[Z] < 0).any() and (d[Z] > 0).any() else [d]):
ax.plot(part[I], part[Z], marker="o", ms=4 if kind != "observed" else 6, color=col, linestyle="--" if kind == "futility" else "-", linewidth=2 if kind == "observed" else 1.5)
ax.plot([], [], color=col, label=name)
ax.set_xlabel(I)
ax.set_ylabel(Z)
ax.legend(fontsize=8)
plt.show()Needs pandas, numpy, matplotlib · reads sequential-boundary-demo.csv · app theme from the optional codesplash helper
# Group-sequential boundaries — Codesplash Chart Lab (recipe "sequential-boundary")
# 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("sequential-boundary-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["series"] = pd.Categorical(df["series"].astype("string"), categories=["efficacy (O'Brien–Fleming)", "futility (non-binding)", "observed z"])
def levels_of(s):
"""Declared level order (categoricals), else order of first appearance."""
if isinstance(s.dtype, pd.CategoricalDtype):
return [v for v in s.cat.categories if (s == v).any()]
return list(dict.fromkeys(s.dropna().astype(str)))
I = "information fraction"
Z = "z statistic"
B = "series"
groups = levels_of(df[B]) if B else [None]
series = []
for name in groups:
d = df if name is None else df[df[B].astype(str) == str(name)]
series.append((name if name is not None else "", d.dropna(subset=[I]).sort_values(I)))
fig = go.Figure()
for i, (name, d) in enumerate(series):
low = str(name).lower()
obs = any(w in low for w in ("observ", "path", "stat"))
fig.add_scatter(x=d[I], y=d[Z], mode="lines+markers", name=name,
line=dict(color="black" if obs else PALETTE[i % len(PALETTE)], dash="dash" if "futil" in low else "solid", width=3 if obs else 2))
fig.add_hline(y=0, line=dict(color="grey", width=1))
fig.update_layout(xaxis_title=I, yaxis_title=Z)
fig.show()Needs pandas, numpy, plotly · reads sequential-boundary-demo.csv · app theme from the optional codesplash helper
# Group-sequential boundaries — Codesplash Chart Lab (recipe "sequential-boundary")
# 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("sequential-boundary-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["series"]] <- factor(df[["series"]], levels = c("efficacy (O'Brien–Fleming)", "futility (non-binding)", "observed z"))
levels_of <- function(v) if (is.factor(v)) levels(droplevels(v)) else unique(as.character(v[!is.na(v)]))
i_col <- "information fraction"
z_col <- "z statistic"
b_col <- "series"
d <- data.frame(i = df[[i_col]], z = df[[z_col]], b = factor(as.character(df[[b_col]]), levels = levels_of(df[[b_col]])))
d <- d[!is.na(d$i) & !is.na(d$z), ]
d$part <- ifelse(d$z < 0 & !grepl("observ|path|stat", tolower(d$b)), "lower", "upper") # two-sided boundaries
d$observed <- grepl("observ|path|stat", tolower(d$b))
p <- ggplot(d, aes(i, z, colour = b, group = interaction(b, part))) +
geom_hline(yintercept = 0, colour = "grey50") +
geom_line(aes(linetype = grepl("futil", tolower(b)), linewidth = observed)) + geom_point(size = 1.8) +
scale_linetype_manual(values = c("solid", "dashed"), guide = "none") + scale_linewidth_manual(values = c(0.7, 1.2), guide = "none") +
scale_colour_manual(values = c(cs_cat[1:2], "black", cs_cat[-(1:2)])) +
labs(x = i_col, y = z_col, colour = NULL) + theme_cs
print(p)Needs ggplot2 · reads sequential-boundary-demo.csv · app theme from the optional codesplashr helper