svginfluence-panel
Influence panel (leave one out)
Is any study an outlier, and how much does the result change without it?
How to read it
- Read rows as studies, across three panels.
- Left: residuals beyond ±1.96 lines are outliers.
- Middle: Cook's distance. Right: the pooled estimate without that study.
- Callout 1: Outlier: a large residual.
- Callout 2: A large Cook's distance.
- Callout 3: The estimate without this study.
Watch out
- Influence isn't a verdict: a very large and good trial may also look influential.
Defaults
No settings: the chart draws one way.
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.
- Residuals beyond ±1.96 are coloured; the dashed line in the third panel is the estimate from all studies (engine control `pooled`).
- Ratios are drawn on a log scale (engine control `log`).
# Influence panel (leave one out) — Codesplash Chart Lab (recipe "influence-panel")
# 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("influence-panel-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["study"] = pd.Categorical(df["study"].astype("string"), categories=["Study 1", "Study 2", "Study 3", "Study 4", "Study 5", "Study 6", "Study 7", "Study 8", "Study 9", "Study 10"])
_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 = "study"
RS = "studentized residual"
COOKS = "Cook's distance"
EST = "risk ratio without the study"
LOW = "low"
HIGH = "high"
d = df.dropna(subset=[RS, EST]).reset_index(drop=True)
y = np.arange(len(d))[::-1]
fig, axes = plt.subplots(1, 3, figsize=(10, max(3, 0.3 * len(d) + 1.2)), sharey=True)
axes[0].axvline(-1.96, color=REF, linestyle="--", linewidth=1)
axes[0].axvline(1.96, color=REF, linestyle="--", linewidth=1)
axes[0].plot(d[RS], y, "o", color=PALETTE[0], markersize=5)
axes[0].set_xlabel(RS)
axes[1].hlines(y, 0, d[COOKS], color=PALETTE[0], linewidth=1.4)
axes[1].plot(d[COOKS], y, "o", color=PALETTE[0], markersize=4)
axes[1].set_xlabel(COOKS)
if LOW and HIGH:
axes[2].hlines(y, d[LOW], d[HIGH], color=PALETTE[0], linewidth=1.2)
axes[2].plot(d[EST], y, "o", color=PALETTE[0], markersize=4)
axes[2].set_xlabel(EST)
axes[0].set_yticks(y, d[LABEL].astype(str))
fig.tight_layout()
plt.show()Needs pandas, numpy, matplotlib · reads influence-panel-demo.csv · app theme from the optional codesplash helper
# Influence panel (leave one out) — Codesplash Chart Lab (recipe "influence-panel")
# 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("influence-panel-demo.csv", keep_default_na=False, na_values=[""]) # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["study"] = pd.Categorical(df["study"].astype("string"), categories=["Study 1", "Study 2", "Study 3", "Study 4", "Study 5", "Study 6", "Study 7", "Study 8", "Study 9", "Study 10"])
_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 = "study"
RS = "studentized residual"
COOKS = "Cook's distance"
EST = "risk ratio without the study"
LOW = "low"
HIGH = "high"
from plotly.subplots import make_subplots
d = df.dropna(subset=[RS, EST]).reset_index(drop=True)
labels = d[LABEL].astype(str)
fig = make_subplots(rows=1, cols=3, shared_yaxes=True, subplot_titles=(RS, COOKS, EST))
fig.add_scatter(x=d[RS], y=labels, mode="markers", marker=dict(color=PALETTE[0]), row=1, col=1)
fig.add_vline(x=-1.96, line=dict(color=REF, dash="dash", width=1), row=1, col=1)
fig.add_vline(x=1.96, line=dict(color=REF, dash="dash", width=1), row=1, col=1)
fig.add_bar(x=d[COOKS], y=labels, orientation="h", marker_color=PALETTE[0], row=1, col=2)
err = dict(type="data", symmetric=False, array=d[HIGH] - d[EST], arrayminus=d[EST] - d[LOW], color=PALETTE[0]) if LOW and HIGH else None
fig.add_scatter(x=d[EST], y=labels, mode="markers", marker=dict(color=PALETTE[0]), error_x=err, row=1, col=3)
fig.update_yaxes(categoryorder="array", categoryarray=list(labels)[::-1])
fig.update_layout(showlegend=False)
fig.show()Needs pandas, numpy, plotly · reads influence-panel-demo.csv · app theme from the optional codesplash helper
# Influence panel (leave one out) — Codesplash Chart Lab (recipe "influence-panel")
# 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("influence-panel-demo.csv", check.names = FALSE, stringsAsFactors = FALSE, na.strings = "") # empty cells are missing; Chart Lab → Code → Download demo CSV
df[["study"]] <- factor(df[["study"]], levels = c("Study 1", "Study 2", "Study 3", "Study 4", "Study 5", "Study 6", "Study 7", "Study 8", "Study 9", "Study 10"))
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 <- "study"
rs_col <- "studentized residual"
cooks_col <- "Cook's distance"
est_col <- "risk ratio without the study"
low_col <- "low"
high_col <- "high"
d <- df[!is.na(df[[rs_col]]) & !is.na(df[[est_col]]), ]
d$study <- factor(as.character(d[[label_col]]), levels = rev(unique(as.character(d[[label_col]]))))
long <- rbind(
data.frame(study = d$study, panel = rs_col, x = d[[rs_col]], low = NA_real_, high = NA_real_),
data.frame(study = d$study, panel = cooks_col, x = d[[cooks_col]], low = 0, high = d[[cooks_col]]),
data.frame(study = d$study, panel = est_col, x = d[[est_col]], low = if (is.null(low_col)) NA_real_ else d[[low_col]], high = if (is.null(high_col)) NA_real_ else d[[high_col]]))
long$panel <- factor(long$panel, levels = c(rs_col, cooks_col, est_col))
limits <- data.frame(panel = factor(rs_col, levels = levels(long$panel)), x = c(-1.96, 1.96))
p <- ggplot(long, aes(x, study)) +
geom_vline(data = limits, aes(xintercept = x), colour = ref_col, linetype = "dashed") +
geom_segment(aes(x = low, xend = high, yend = study), colour = cs_cat[1], linewidth = 0.4, na.rm = TRUE) +
geom_point(colour = cs_cat[1], size = 1.8) +
facet_wrap(~ panel, nrow = 1, scales = "free_x") +
labs(x = NULL, y = NULL) + theme_cs
print(p)Needs ggplot2 · reads influence-panel-demo.csv · app theme from the optional codesplashr helper