svgmeta-funnel
Funnel plot (contour-enhanced)
Are small studies' effects distributed symmetrically around the pooled effect?
How to read it
- Read y as precision: large studies at the top.
- Without bias, points form a symmetric funnel around the pooled effect.
- Look for a missing corner: small studies with unfavourable results may be absent.
- Callout 1: Precise studies at the top.
- Callout 2: Imputed studies fill the gap.
- Callout 3: A missing corner.
Watch out
- Asymmetry isn't only publication bias: true heterogeneity and small-study differences produce it too.
Defaults
- Significance contours
- On
- Shade where a study would be significant at p < .10, .05 and .01 (two-sided, against zero).
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.
- The y axis is the standard error, reversed so the most precise studies sit at the top (Sterne & Egger 2001).
- Dashed lines: the pooled estimate ± 1.96·SE (engine control `center`). Shaded wedges: |effect| ≥ z·SE for p = .10, .05, .01 around zero (Peters et al. 2008).
- Open circles are studies imputed by trim-and-fill; the dotted vertical line is the adjusted estimate. The solid coloured line is Egger's regression (effect = intercept + slope·SE).
# Funnel plot (contour-enhanced) — Codesplash Chart Lab (recipe "meta-funnel")
# controls: contours=true
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import stats
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("meta-funnel-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
EST = "log risk ratio"
SE = "standard error"
KIND = "study"
CENTER, ADJUSTED, CONTOURS = None, None, True
EGGER_B0, EGGER_B1 = None, None
d = df.dropna(subset=[EST, SE])
imputed = d[KIND].astype(str).eq("imputed") if KIND else pd.Series(False, index=d.index)
se_max = d[SE].max() * 1.08
fig, ax = plt.subplots(figsize=(7, 5.5))
if CONTOURS: # where a study would be significant against zero (p 0.10–0.05, 0.05–0.01, < 0.01)
z = stats.norm.ppf([0.95, 0.975, 0.995])
span = max(d[EST].abs().max(), z[2] * se_max) * 1.05
for lo, hi, alpha in ((z[0], z[1], 0.10), (z[1], z[2], 0.18), (z[2], None, 0.28)):
outer = [span, span] if hi is None else [0, hi * se_max]
for side in (-1, 1):
ax.fill_betweenx([0, se_max], [0, side * lo * se_max], [side * v for v in outer], color=REF, alpha=alpha, lw=0)
if CENTER is not None:
z95 = stats.norm.ppf(0.975)
ax.plot([CENTER - z95 * se_max, CENTER, CENTER + z95 * se_max], [se_max, 0, se_max], color=REF, linestyle="--", linewidth=1)
ax.axvline(CENTER, color=REF, linewidth=1)
if ADJUSTED is not None:
ax.axvline(ADJUSTED, color=PALETTE[1], linestyle=":", linewidth=1.2, label="adjusted")
if EGGER_B0 is not None and EGGER_B1 is not None:
ax.plot([EGGER_B0, EGGER_B0 + EGGER_B1 * se_max], [0, se_max], color=PALETTE[2], linewidth=1.2, label="Egger line")
ax.scatter(d.loc[~imputed, EST], d.loc[~imputed, SE], s=28, color=PALETTE[0], zorder=3, label="study")
if imputed.any():
ax.scatter(d.loc[imputed, EST], d.loc[imputed, SE], s=28, facecolors="none", edgecolors=PALETTE[0], zorder=3, label="imputed")
ax.set_ylim(se_max, 0) # the most precise studies at the top
ax.set_xlabel(EST)
ax.set_ylabel(SE)
ax.legend(fontsize=8, loc="lower right")
plt.show()Needs pandas, numpy, matplotlib, scipy · reads meta-funnel-demo.csv · app theme from the optional codesplash helper
# Funnel plot (contour-enhanced) — Codesplash Chart Lab (recipe "meta-funnel")
# controls: contours=true
import numpy as np
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from scipy import stats
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("meta-funnel-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
_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")
EST = "log risk ratio"
SE = "standard error"
KIND = "study"
LABEL = "study"
CENTER, ADJUSTED, CONTOURS = None, None, True
d = df.dropna(subset=[EST, SE])
imputed = d[KIND].astype(str).eq("imputed") if KIND else pd.Series(False, index=d.index)
se_max = d[SE].max() * 1.08
fig = go.Figure()
if CONTOURS: # where a study would be significant against zero
for zz, name in zip(stats.norm.ppf([0.995, 0.975, 0.95]), ("p = 0.01", "p = 0.05", "p = 0.10")):
fig.add_scatter(x=[-zz * se_max, 0, zz * se_max], y=[se_max, 0, se_max], mode="lines", line=dict(color=GREY, width=1), name=name)
if CENTER is not None:
z95 = stats.norm.ppf(0.975)
fig.add_scatter(x=[CENTER - z95 * se_max, CENTER, CENTER + z95 * se_max], y=[se_max, 0, se_max], mode="lines", line=dict(color=REF, dash="dash", width=1), name="pseudo 95% limits")
if ADJUSTED is not None:
fig.add_vline(x=ADJUSTED, line=dict(color=PALETTE[1], dash="dot"))
text = d[LABEL].astype(str) if LABEL else None
fig.add_scatter(x=d.loc[~imputed, EST], y=d.loc[~imputed, SE], mode="markers", marker=dict(size=8, color=PALETTE[0]), name="study", text=None if text is None else text[~imputed])
if imputed.any():
fig.add_scatter(x=d.loc[imputed, EST], y=d.loc[imputed, SE], mode="markers", marker=dict(size=8, color="rgba(0,0,0,0)", line=dict(color=PALETTE[0], width=1.5)), name="imputed")
fig.update_yaxes(range=[se_max, 0], title=SE) # the most precise studies at the top
fig.update_xaxes(title=EST)
fig.show()Needs pandas, numpy, plotly, scipy · reads meta-funnel-demo.csv · app theme from the optional codesplash helper
# Funnel plot (contour-enhanced) — Codesplash Chart Lab (recipe "meta-funnel")
# controls: contours=true
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("meta-funnel-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["study"]] <- factor(df[["study"]])
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
est_col <- "log risk ratio"
se_col <- "standard error"
kind_col <- "study"
center <- NULL; adjusted <- NULL; contours <- TRUE
egger_b0 <- NULL; egger_b1 <- NULL
d <- df[!is.na(df[[est_col]]) & !is.na(df[[se_col]]), ]
d$est <- d[[est_col]]; d$se <- d[[se_col]]
d$kind <- if (is.null(kind_col)) "study" else ifelse(as.character(d[[kind_col]]) == "imputed", "imputed", "study")
se_max <- max(d$se) * 1.08
tri <- function(mid, z) data.frame(x = c(mid - z * se_max, mid, mid + z * se_max), y = c(se_max, 0, se_max))
p <- ggplot()
if (contours) for (z in qnorm(c(0.995, 0.975, 0.95))) p <- p + geom_polygon(data = tri(0, z), aes(x, y), fill = NA, colour = grey_col, linewidth = 0.3)
if (!is.null(center)) {
p <- p + geom_path(data = tri(center, qnorm(0.975)), aes(x, y), colour = ref_col, linetype = "dashed") +
geom_vline(xintercept = center, colour = ref_col)
}
if (!is.null(adjusted)) p <- p + geom_vline(xintercept = adjusted, colour = cs_cat[2], linetype = "dotted")
if (!is.null(egger_b0) && !is.null(egger_b1)) p <- p + annotate("segment", x = egger_b0, xend = egger_b0 + egger_b1 * se_max, y = 0, yend = se_max, colour = cs_cat[3])
p <- p + geom_point(data = d, aes(est, se, shape = kind), colour = cs_cat[1], size = 2.2) +
scale_shape_manual(values = c(study = 16, imputed = 1)) +
scale_y_reverse(limits = c(se_max, 0)) + # the most precise studies at the top
labs(x = est_col, y = se_col, shape = NULL) + theme_cs
print(p)Needs ggplot2 · reads meta-funnel-demo.csv · app theme from the optional codesplashr helper