svgcumulative-forest
Cumulative meta-analysis
When did the evidence become clear, and has it drifted as studies accumulated?
How to read it
- Read rows top down as studies get added.
- Watch when the interval stops crossing the reference.
- A drifting estimate suggests earlier studies differ from later ones.
- Callout 1: With the first study alone.
- Callout 2: All studies: the final pooled estimate.
- Callout 3: The reference line.
Watch out
- Looking repeatedly inflates false positives, as with interim analyses in a trial.
Defaults
- Reference (null) value
- 0
- The value that means no effect, such as 0 for a difference or 1 for a ratio.
- Range -1,000 to 1,000, step 0.1
- Log scale (ratios)
- Off
- Use a log axis, the natural scale for ratios: 2 and ½ sit the same distance from 1.
Pinned in the code
- Draws the meta-analysis engine's numbers as given (codesplash.stats.meta in Python ≡ codesplashr in R); the chart computes nothing statistical.
- Row i is the meta-analysis of the first i studies in the engine's order; intervals narrow as evidence accumulates.
- Repeated looks inflate false positives: a cumulative plot describes history, it is not a sequential test.
# Cumulative meta-analysis — Codesplash Chart Lab (recipe "cumulative-forest")
# controls: reference=0, log=false
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("cumulative-forest-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["added study"] = pd.Categorical(df["added study"].astype("string"), categories=["+ Aronson 1948", "+ Ferguson 1949", "+ Rosenthal 1960", "+ Hart 1977", "+ Frimodt 1973", "+ Stein 1953", "+ Vandiviere 1973", "+ Madras 1980", "+ Coetzee 1968", "+ Rosenthal 1961", "+ Comstock 1974", "+ Comstock 1969"])
_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")
LABEL = "added study"
EST = "risk ratio"
LOW = "low"
HIGH = "high"
LOG, REFERENCE = False, 0 # the "no effect" value: 0 for differences, 1 for ratios
d = df.dropna(subset=[EST]).reset_index(drop=True)
y = np.arange(len(d))[::-1] # first row at the top
fig, ax = plt.subplots(figsize=(8, max(3, 0.32 * len(d) + 1.2)))
ax.axvline(REFERENCE, color=REF, linestyle="--", linewidth=1)
ax.hlines(y, d[LOW], d[HIGH], color=PALETTE[0], linewidth=1.4)
ax.plot(d[EST], y, "o", color=PALETTE[0], markersize=5)
if LOG:
ax.set_xscale("log")
ax.set_yticks(y, d[LABEL].astype(str))
ax.set_xlabel(EST + " (each row pools the studies so far)")
fig.tight_layout()
plt.show()Needs pandas, numpy, matplotlib · reads cumulative-forest-demo.csv · app theme from the optional codesplash helper
# Cumulative meta-analysis — Codesplash Chart Lab (recipe "cumulative-forest")
# controls: reference=0, log=false
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("cumulative-forest-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["added study"] = pd.Categorical(df["added study"].astype("string"), categories=["+ Aronson 1948", "+ Ferguson 1949", "+ Rosenthal 1960", "+ Hart 1977", "+ Frimodt 1973", "+ Stein 1953", "+ Vandiviere 1973", "+ Madras 1980", "+ Coetzee 1968", "+ Rosenthal 1961", "+ Comstock 1974", "+ Comstock 1969"])
_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")
LABEL = "added study"
EST = "risk ratio"
LOW = "low"
HIGH = "high"
LOG, REFERENCE = False, 0 # the "no effect" value: 0 for differences, 1 for ratios
d = df.dropna(subset=[EST]).reset_index(drop=True)
y = np.arange(len(d))[::-1] # first row at the top
fig = go.Figure(go.Scatter(x=d[EST], y=y, mode="markers", marker=dict(size=8, color=PALETTE[0]), text=d[LABEL].astype(str),
error_x=dict(type="data", symmetric=False, array=d[HIGH] - d[EST], arrayminus=d[EST] - d[LOW], color=PALETTE[0])))
fig.add_vline(x=REFERENCE, line=dict(color=REF, dash="dash", width=1))
fig.update_yaxes(tickmode="array", tickvals=list(y), ticktext=list(d[LABEL].astype(str)))
fig.update_xaxes(type="log" if LOG else "linear", title=EST + " (each row pools the studies so far)")
fig.show()Needs pandas, numpy, plotly · reads cumulative-forest-demo.csv · app theme from the optional codesplash helper
# Cumulative meta-analysis — Codesplash Chart Lab (recipe "cumulative-forest")
# controls: reference=0, log=false
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("cumulative-forest-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["added study"]] <- factor(df[["added study"]], levels = c("+ Aronson 1948", "+ Ferguson 1949", "+ Rosenthal 1960", "+ Hart 1977", "+ Frimodt 1973", "+ Stein 1953", "+ Vandiviere 1973", "+ Madras 1980", "+ Coetzee 1968", "+ Rosenthal 1961", "+ Comstock 1974", "+ Comstock 1969"))
tok <- if (has_cs) codesplashr::cs_palette(dark = FALSE) else list()
seq_ramp <- if (is.null(tok$sequential)) c("#eff6fd", "#1a469d") else tok$sequential # low → high
div_ramp <- if (is.null(tok$diverging)) c("#c13e2e", "#f3f5f8", "#0859ac") else tok$diverging # −, 0, +
ref_col <- if (is.null(tok$reference)) "#4e5661" else tok$reference
grey_col <- if (is.null(tok$dim)) "#ced1d6" else tok$dim
label_col <- "added study"
est_col <- "risk ratio"
low_col <- "low"
high_col <- "high"
use_log <- FALSE; reference <- 0 # the "no effect" value: 0 for differences, 1 for ratios
keep <- !is.na(df[[est_col]])
d <- data.frame(label = as.character(df[[label_col]][keep]), est = df[[est_col]][keep], low = df[[low_col]][keep], high = df[[high_col]][keep])
d$row <- rev(seq_len(nrow(d))) # first row at the top
p <- ggplot(d, aes(est, row)) +
geom_vline(xintercept = reference, colour = ref_col, linetype = "dashed") +
geom_segment(aes(x = low, xend = high, yend = row), colour = cs_cat[1], linewidth = 0.5) +
geom_point(colour = cs_cat[1], size = 2) +
scale_y_continuous(breaks = d$row, labels = d$label) +
labs(x = paste0(est_col, " (each row pools the studies so far)"), y = NULL) + theme_cs
if (use_log) p <- p + scale_x_log10()
print(p)Needs ggplot2 · reads cumulative-forest-demo.csv · app theme from the optional codesplashr helper