Does one study drive the result?
Use leave-one-out analysis, Baujat plots and cumulative meta-analysis to see whether the conclusion rests on a few studies.
What runs in CodeSplash
- Influence and sensitivity of a meta-analysis Verified in Python and R
You will be able to
- Run a leave-one-out analysis and report how far the estimate moves
- Read a Baujat plot for contribution to heterogeneity and influence
- Explain what a cumulative meta-analysis shows and what it can't
Read first
One study can carry a lot
ReadA pooled estimate is an average, and averages have leverage points. Before you trust one, remove each study in turn and pool again.
That is a leave-one-out analysis. For the BCG log risk ratios, the pooled value is −0.715. Removing any one trial keeps it between −0.795 and −0.628.
Which study matters most?
PredictPredict first
Influence on a pooled estimate depends on what?
Reveal
Both. An extreme result with almost no weight hardly moves the average, and neither does a heavy study sitting right on it. In these trials, the most influential is Hart & Sutherland 1977, with Cook's distance 0.23.
Read the panel
ReadWithout one study at a time the pooled risk ratio ranges 0.452 to 0.533 (all studies 0.489); most influential: Hart & Sutherland 1977.
- Largest Cook's distance
- 0.2295
- Studies with |residual| > 1.96
- 0
Plots
View data
| study | contribution to Q | influence on the pooled estimate |
|---|---|---|
| Aronson 1948 | 0.6472 | 0.0015 |
| Ferguson & Simes 1949 | 6.857 | 0.1121 |
| Rosenthal et al 1960 | 2.028 | 0.0243 |
| Hart & Sutherland 1977 | 51.107 | 0.2378 |
| Frimodt-Moller et al 1973 | 0.8838 | 0.0670 |
| Stein & Aronson 1953 | 18.335 | 0.0003 |
| Vandiviere et al 1973 | 6.356 | 0.1079 |
| TPT Madras 1980 | 49.368 | 0.1990 |
| Coetzee & Berjak 1968 | 0.0271 | 0.0184 |
| Rosenthal et al 1961 | 12.127 | 0.1114 |
| Comstock et al 1974 | 0.6661 | 0.0490 |
| Comstock & Webster 1969 | 1.442 | 0.0618 |
| Comstock et al 1976 | 2.388 | 0.1153 |
View data
| Cook's distance | risk ratio without the study | high | study | low | studentized residual |
|---|---|---|---|---|---|
| 0.0017 | 0.4931 | 0.7155 | Aronson 1948 | 0.3398 | −0.2181 |
| 0.1132 | 0.5199 | 0.7409 | Ferguson & Simes 1949 | 0.3649 | −1.292 |
| 0.0260 | 0.5038 | 0.7250 | Rosenthal et al 1960 | 0.3501 | −0.7547 |
| 0.2295 | 0.5334 | 0.7541 | Hart & Sutherland 1977 | 0.3774 | −1.451 |
| 0.0762 | 0.4657 | 0.6782 | Frimodt-Moller et al 1973 | 0.3198 | 0.8477 |
| 0.0004 | 0.4912 | 0.7273 | Stein & Aronson 1953 | 0.3318 | −0.1180 |
| 0.1087 | 0.5193 | 0.7397 | Vandiviere et al 1973 | 0.3646 | −1.304 |
| 0.1992 | 0.4517 | 0.6426 | TPT Madras 1980 | 0.3175 | 1.450 |
| 0.0220 | 0.4765 | 0.7007 | Coetzee & Berjak 1968 | 0.3241 | 0.4076 |
| 0.1170 | 0.5205 | 0.7469 | Rosenthal et al 1961 | 0.3627 | −1.128 |
| 0.0581 | 0.4687 | 0.6879 | Comstock et al 1974 | 0.3193 | 0.6691 |
| 0.0634 | 0.4678 | 0.6684 | Comstock & Webster 1969 | 0.3274 | 1.290 |
| 0.1228 | 0.4595 | 0.6611 | Comstock et al 1976 | 0.3194 | 1.188 |
View data
| risk ratio | high | added study | low |
|---|---|---|---|
| 0.4109 | 1.257 | + Aronson 1948 | 0.1343 |
| 0.2658 | 0.5268 | + Ferguson & Simes 1949 | 0.1341 |
| 0.3783 | 0.6120 | + Stein & Aronson 1953 | 0.2338 |
| 0.3675 | 0.5681 | + Rosenthal et al 1960 | 0.2377 |
| 0.3324 | 0.4916 | + Rosenthal et al 1961 | 0.2248 |
| 0.3778 | 0.5457 | + Coetzee & Berjak 1968 | 0.2615 |
| 0.4061 | 0.5901 | + Comstock & Webster 1969 | 0.2794 |
| 0.4545 | 0.6686 | + Frimodt-Moller et al 1973 | 0.3089 |
| 0.4208 | 0.6182 | + Vandiviere et al 1973 | 0.2864 |
| 0.4560 | 0.6491 | + Comstock et al 1974 | 0.3204 |
| 0.4925 | 0.6987 | + Comstock et al 1976 | 0.3472 |
| 0.4517 | 0.6426 | + Hart & Sutherland 1977 | 0.3175 |
| 0.4894 | 0.6962 | + TPT Madras 1980 | 0.3441 |
Assumptions
- Independent estimates — One estimate per study is assumed.
Leave one out (risk ratio, 95% CI)
| Left out | Pooled | CI low | CI high | τ² | I² (%) | Studentized residual | Cook's distance |
|---|---|---|---|---|---|---|---|
| Aronson 1948 | 0.4931 | 0.3398 | 0.7155 | 0.3362 | 93.226 | −0.2181 | 0.0017 |
| Ferguson & Simes 1949 | 0.5199 | 0.3649 | 0.7409 | 0.2926 | 92.254 | −1.292 | 0.1132 |
| Rosenthal et al 1960 | 0.5038 | 0.3501 | 0.7250 | 0.3207 | 92.935 | −0.7547 | 0.0260 |
| Hart & Sutherland 1977 | 0.5334 | 0.3774 | 0.7541 | 0.2628 | 90.412 | −1.451 | 0.2295 |
| Frimodt-Moller et al 1973 | 0.4657 | 0.3198 | 0.6782 | 0.3278 | 92.763 | 0.8477 | 0.0762 |
| Stein & Aronson 1953 | 0.4912 | 0.3318 | 0.7273 | 0.3596 | 90.912 | −0.1180 | 0.0004 |
| Vandiviere et al 1973 | 0.5193 | 0.3646 | 0.7397 | 0.2930 | 92.278 | −1.304 | 0.1087 |
| TPT Madras 1980 | 0.4517 | 0.3175 | 0.6426 | 0.2732 | 87.031 | 1.450 | 0.1992 |
| Coetzee & Berjak 1968 | 0.4765 | 0.3241 | 0.7007 | 0.3495 | 93.213 | 0.4076 | 0.0220 |
| Rosenthal et al 1961 | 0.5205 | 0.3627 | 0.7469 | 0.2987 | 92.232 | −1.128 | 0.1170 |
| Comstock et al 1974 | 0.4687 | 0.3193 | 0.6879 | 0.3405 | 91.811 | 0.6691 | 0.0581 |
| Comstock & Webster 1969 | 0.4678 | 0.3274 | 0.6684 | 0.3082 | 92.678 | 1.290 | 0.0634 |
| Comstock et al 1976 | 0.4595 | 0.3194 | 0.6611 | 0.3037 | 92.344 | 1.188 | 0.1228 |
Cumulative pooled estimate
| Study added | Pooled | CI low | CI high |
|---|---|---|---|
| + Aronson 1948 | 0.4109 | 0.1343 | 1.257 |
| + Ferguson & Simes 1949 | 0.2658 | 0.1341 | 0.5268 |
| + Stein & Aronson 1953 | 0.3783 | 0.2338 | 0.6120 |
| + Rosenthal et al 1960 | 0.3675 | 0.2377 | 0.5681 |
| + Rosenthal et al 1961 | 0.3324 | 0.2248 | 0.4916 |
| + Coetzee & Berjak 1968 | 0.3778 | 0.2615 | 0.5457 |
| + Comstock & Webster 1969 | 0.4061 | 0.2794 | 0.5901 |
| + Frimodt-Moller et al 1973 | 0.4545 | 0.3089 | 0.6686 |
| + Vandiviere et al 1973 | 0.4208 | 0.2864 | 0.6182 |
| + Comstock et al 1974 | 0.4560 | 0.3204 | 0.6491 |
| + Comstock et al 1976 | 0.4925 | 0.3472 | 0.6987 |
| + Hart & Sutherland 1977 | 0.4517 | 0.3175 | 0.6426 |
| + TPT Madras 1980 | 0.4894 | 0.3441 | 0.6962 |
- A study is worth a closer look when its studentized residual exceeds ±1.96 or its Cook's distance stands apart; never drop studies just to reduce heterogeneity.
The exact R script · R R version 4.5.1 (2025-06-13)
# Influence and sensitivity of a meta-analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method meta.influence 1.0.1 · spec 6fb09b86419432d8
# Dataset: m1_bcg (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
library(codesplashr) # cs_meta_* (twins of codesplash.stats.meta)
# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/m1_bcg.parquet", col_select = c("trial", "events_1", "total_1", "events_2", "total_2", "year")))
n_input <- nrow(df)
df[["trial"]] <- factor(df[["trial"]], levels = c("Aronson 1948", "Ferguson & Simes 1949", "Rosenthal et al 1960", "Hart & Sutherland 1977", "Frimodt-Moller et al 1973", "Stein & Aronson 1953", "Vandiviere et al 1973", "TPT Madras 1980", "Coetzee & Berjak 1968", "Rosenthal et al 1961", "Comstock et al 1974", "Comstock & Webster 1969", "Comstock et al 1976")) # stored level order
df <- df[stats::complete.cases(df[c("trial", "events_1", "total_1", "events_2", "total_2", "year")]), , drop = FALSE] # listwise deletion
df[] <- lapply(df, function(x) if (is.factor(x)) droplevels(x) else x)
n_dropped <- n_input - nrow(df)
warnings <- list()
if (n_dropped > 0) {
warnings <- c(warnings, cs_warning("CS_W_ROWS_DROPPED", dropped = n_dropped, total = n_input))
}
if (n_input > 0 && nrow(df) == 0) cs_error("CS_E_NO_ROWS")
cs_check_finite_columns(df, c("trial", "events_1", "total_1", "events_2", "total_2", "year")) # infinite values stop the run (registry/errors.yaml)
# %% Studies
design <- "binary" # inferred from the bound columns
measure <- "RR"
cols <- list(
events_1 = as.numeric(df[["events_1"]]),
total_1 = as.numeric(df[["total_1"]]),
events_2 = as.numeric(df[["events_2"]]),
total_2 = as.numeric(df[["total_2"]]),
NULL
)
cols <- Filter(Negate(is.null), cols)
es <- cs_meta_escalc(design, measure, cols, zero_cells = "only0", drop00 = TRUE, ci_level = 0.95)
measure <- es$measure
labels_all <- as.character(df[["trial"]])
keep <- es$keep
left_out <- labels_all[!keep]
idx <- which(keep)
y <- es$yi[idx]; v <- es$vi[idx]
labels <- labels_all[idx]
k <- length(y)
if (k < 2) cs_error("CS_E_TOO_FEW_ROWS", what = "A meta-analysis", min = 2, n = k) # one usable study can't be pooled
if (length(left_out)) {
warnings <- c(warnings, paste0(sprintf("Left out (%d): ", length(left_out)), paste(left_out, collapse = ", "),
if (design == "binary") " — no events (or only events) in both arms." else " — effect or variance not computable."))
}
bt <- cs_meta_back(measure)
MEASURE_LABEL <- c(GEN = "effect", LOG = "log ratio", OR = "log odds ratio", RR = "log risk ratio", RD = "risk difference",
MD = "mean difference", SMD = "Hedges' g", ZCOR = "Fisher's z", COR = "correlation")[[measure]]
RATIO <- measure %in% c("OR", "RR", "LOG")
# What a back-transformed number is: a ratio, not a log ratio; a correlation, not Fisher's z.
DISPLAY_LABEL <- if (measure %in% c("OR", "RR", "LOG", "ZCOR")) c(OR = "odds ratio", RR = "risk ratio", LOG = "ratio", ZCOR = "correlation")[[measure]] else MEASURE_LABEL
if (k < 3) cs_error("CS_E_TOO_FEW_ROWS", what = "Leave-one-out influence", min = 3, n = k) # each refit leaves out one study and needs two
# %% Influence
conf <- 0.95
fit_method <- if ("random" == "fixed") "FE" else "REML"
test <- "z"
inf <- cs_meta_influence(y, v, method = fit_method, test = test, level = conf)
full <- inf$full; rows <- inf$rows
est <- full$beta[1]
rstud <- vapply(rows, function(r) r$rstudent, numeric(1))
cooks <- vapply(rows, function(r) r$cooks, numeric(1))
loo <- vapply(rows, function(r) r$est, numeric(1))
top <- which.max(cooks)
ord <- order(df[["year"]][idx], method = "radix") # cumulative order: year
cum <- cs_meta_cumulative(y, v, ord, method = fit_method, test = test, level = conf)
# %% Assumptions
assumptions <- list(list(key = "independence", label = "Independent estimates", status = "info", detail = "One estimate per study is assumed."))
# %% Result
disp <- if (RATIO) sub("log ", "", MEASURE_LABEL) else MEASURE_LABEL
values <- list(k = k, est = est, tau2 = full$tau2, i2 = full$i2, n_outlying = sum(abs(rstud) > 1.96), max_abs_rstudent = max(abs(rstud)),
max_cooks = cooks[top], most_influential = labels[top], loo_min = min(loo), loo_max = max(loo), measure = measure, measure_label = MEASURE_LABEL)
for (i in seq_along(rows)) {
r <- rows[[i]]; l <- labels[i]
values[[sprintf("loo_est[%s]", l)]] <- r$est; values[[sprintf("loo_tau2[%s]", l)]] <- r$tau2; values[[sprintf("rstudent[%s]", l)]] <- r$rstudent
values[[sprintf("cooks[%s]", l)]] <- r$cooks; values[[sprintf("baujat_x[%s]", l)]] <- r$baujat_x; values[[sprintf("baujat_y[%s]", l)]] <- r$baujat_y
}
table_rows <- lapply(seq_along(rows), function(i) { r <- rows[[i]]
list(study = labels[i], loo = bt(r$est), low = bt(r$ci_low), high = bt(r$ci_high), tau2 = r$tau2, i2 = r$i2, rstudent = r$rstudent, cooks = r$cooks) })
charts <- list(
cs_chart("baujat", "baujat", "Contribution to heterogeneity against influence on the result",
list(x = cs_col("contribution to Q", vapply(rows, function(r) r$baujat_x, numeric(1))),
y = cs_col("influence on the pooled estimate", vapply(rows, function(r) r$baujat_y, numeric(1))), label = cs_col("study", labels))),
cs_chart("influence", "influence-panel", "Leave-one-out diagnostics",
list(label = cs_col("study", labels), rstudent = cs_col("studentized residual", rstud), cooks = cs_col("Cook's distance", cooks),
estimate = cs_col(paste(disp, "without the study"), vapply(table_rows, function(t) t$loo, numeric(1))),
low = cs_col("low", vapply(table_rows, function(t) t$low, numeric(1))), high = cs_col("high", vapply(table_rows, function(t) t$high, numeric(1)))),
controls = list(pooled = bt(est), log = RATIO))
)
cum_rows <- list()
if (!is.null(cum)) {
for (j in seq_along(cum)) {
c <- cum[[j]]; l <- labels[ord[j]]
values[[sprintf("cum_est[%s]", l)]] <- c$est
cum_rows[[j]] <- list(study = paste("+", l), estimate = bt(c$est), low = bt(c$ci_low), high = bt(c$ci_high))
}
charts[[length(charts) + 1]] <- cs_chart("cumulative", "cumulative-forest", "Cumulative meta-analysis",
list(label = cs_col("added study", vapply(cum_rows, function(r) r$study, character(1))), estimate = cs_col(disp, vapply(cum_rows, function(r) r$estimate, numeric(1))),
low = cs_col("low", vapply(cum_rows, function(r) r$low, numeric(1))), high = cs_col("high", vapply(cum_rows, function(r) r$high, numeric(1)))),
controls = list(reference = if (RATIO) 1 else 0, log = RATIO))
}
tables <- list(list(key = "loo", title = sprintf("Leave one out (%s, %.0f%% CI)", disp, conf * 100),
columns = list(list(key = "study", label = "Left out", type = "string"), list(key = "loo", label = "Pooled", type = "number"),
list(key = "low", label = "CI low", type = "number"), list(key = "high", label = "CI high", type = "number"),
list(key = "tau2", label = "τ²", type = "number"), list(key = "i2", label = "I² (%)", type = "number"),
list(key = "rstudent", label = "Studentized residual", type = "number"), list(key = "cooks", label = "Cook's distance", type = "number")),
rows = table_rows))
if (length(cum_rows)) tables[[2]] <- list(key = "cumulative", title = "Cumulative pooled estimate",
columns = list(list(key = "study", label = "Study added", type = "string"), list(key = "estimate", label = "Pooled", type = "number"),
list(key = "low", label = "CI low", type = "number"), list(key = "high", label = "CI high", type = "number")), rows = cum_rows)
cs_publish(list(
method = "meta.influence",
methodVersion = "1.0.1",
title = sprintf("Influence diagnostics for %d studies", k),
engine = cs_engine_info("stats", "nanoparquet"),
n = k,
summary = sprintf("Without one study at a time the pooled %s ranges %s to %s (all studies %s); most influential: %s.", disp, format(signif(bt(min(loo)), 3)),
format(signif(bt(max(loo)), 3)), format(signif(bt(est), 3)), labels[top]),
statistics = list(list(key = "max_cooks", label = "Largest Cook's distance", value = cooks[top]),
list(key = "n_outlying", label = "Studies with |residual| > 1.96", value = sum(abs(rstud) > 1.96), format = "integer")),
tables = tables,
assumptions = assumptions,
warnings = warnings,
notes = list("A study is worth a closer look when its studentized residual exceeds ±1.96 or its Cook's distance stands apart; never drop studies just to reduce heterogeneity."),
charts = charts,
values = values
))
Without one study at a time the pooled risk ratio ranges 0.452 to 0.533 (all studies 0.489); most influential: Hart & Sutherland 1977.
- Largest Cook's distance
- 0.2295
- Studies with |residual| > 1.96
- 0
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Independent estimates — One estimate per study is assumed.
Leave one out (risk ratio, 95% CI)
| Left out | Pooled | CI low | CI high | τ² | I² (%) | Studentized residual | Cook's distance |
|---|---|---|---|---|---|---|---|
| Aronson 1948 | 0.4931 | 0.3398 | 0.7155 | 0.3362 | 93.226 | −0.2181 | 0.0017 |
| Ferguson & Simes 1949 | 0.5199 | 0.3649 | 0.7409 | 0.2926 | 92.254 | −1.292 | 0.1132 |
| Rosenthal et al 1960 | 0.5038 | 0.3501 | 0.7250 | 0.3207 | 92.935 | −0.7547 | 0.0260 |
| Hart & Sutherland 1977 | 0.5334 | 0.3774 | 0.7541 | 0.2628 | 90.412 | −1.451 | 0.2295 |
| Frimodt-Moller et al 1973 | 0.4657 | 0.3198 | 0.6782 | 0.3278 | 92.763 | 0.8477 | 0.0762 |
| Stein & Aronson 1953 | 0.4912 | 0.3318 | 0.7273 | 0.3596 | 90.912 | −0.1180 | 0.0004 |
| Vandiviere et al 1973 | 0.5193 | 0.3646 | 0.7397 | 0.2930 | 92.278 | −1.304 | 0.1087 |
| TPT Madras 1980 | 0.4517 | 0.3175 | 0.6426 | 0.2732 | 87.031 | 1.450 | 0.1992 |
| Coetzee & Berjak 1968 | 0.4765 | 0.3241 | 0.7007 | 0.3495 | 93.213 | 0.4076 | 0.0220 |
| Rosenthal et al 1961 | 0.5205 | 0.3627 | 0.7469 | 0.2987 | 92.232 | −1.128 | 0.1170 |
| Comstock et al 1974 | 0.4687 | 0.3193 | 0.6879 | 0.3405 | 91.811 | 0.6691 | 0.0581 |
| Comstock & Webster 1969 | 0.4678 | 0.3274 | 0.6684 | 0.3082 | 92.678 | 1.290 | 0.0634 |
| Comstock et al 1976 | 0.4595 | 0.3194 | 0.6611 | 0.3037 | 92.344 | 1.188 | 0.1228 |
Cumulative pooled estimate
| Study added | Pooled | CI low | CI high |
|---|---|---|---|
| + Aronson 1948 | 0.4109 | 0.1343 | 1.257 |
| + Ferguson & Simes 1949 | 0.2658 | 0.1341 | 0.5268 |
| + Stein & Aronson 1953 | 0.3783 | 0.2338 | 0.6120 |
| + Rosenthal et al 1960 | 0.3675 | 0.2377 | 0.5681 |
| + Rosenthal et al 1961 | 0.3324 | 0.2248 | 0.4916 |
| + Coetzee & Berjak 1968 | 0.3778 | 0.2615 | 0.5457 |
| + Comstock & Webster 1969 | 0.4061 | 0.2794 | 0.5901 |
| + Frimodt-Moller et al 1973 | 0.4545 | 0.3089 | 0.6686 |
| + Vandiviere et al 1973 | 0.4208 | 0.2864 | 0.6182 |
| + Comstock et al 1974 | 0.4560 | 0.3204 | 0.6491 |
| + Comstock et al 1976 | 0.4925 | 0.3472 | 0.6987 |
| + Hart & Sutherland 1977 | 0.4517 | 0.3175 | 0.6426 |
| + TPT Madras 1980 | 0.4894 | 0.3441 | 0.6962 |
- A study is worth a closer look when its studentized residual exceeds ±1.96 or its Cook's distance stands apart; never drop studies just to reduce heterogeneity.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Influence and sensitivity of a meta-analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method meta.influence 1.0.1 · spec 6fb09b86419432d8
# Dataset: m1_bcg (version 1)
# Runs on its own: outside the app, cs.publish() writes $CS_RESULT_PATH or prints the result JSON.
# %% Setup
import numpy as np
import pandas as pd
import codesplash as cs
from codesplash.stats import meta # twins of codesplashr::cs_meta_*
# %% Data
df = pd.read_parquet("tests/parity/fixtures/m1_bcg.parquet", columns=["trial", "events_1", "total_1", "events_2", "total_2", "year"])
n_input = len(df)
df["trial"] = pd.Categorical(df["trial"], categories=["Aronson 1948", "Ferguson & Simes 1949", "Rosenthal et al 1960", "Hart & Sutherland 1977", "Frimodt-Moller et al 1973", "Stein & Aronson 1953", "Vandiviere et al 1973", "TPT Madras 1980", "Coetzee & Berjak 1968", "Rosenthal et al 1961", "Comstock et al 1974", "Comstock & Webster 1969", "Comstock et al 1976"]) # stored level order
df = df.dropna(subset=["trial", "events_1", "total_1", "events_2", "total_2", "year"]) # listwise deletion over the analysis columns
df["trial"] = df["trial"].cat.remove_unused_categories()
n_dropped = n_input - len(df)
warnings = []
if n_dropped:
warnings.append(cs.cs_warning("CS_W_ROWS_DROPPED", dropped=n_dropped, total=n_input))
if n_input and not len(df):
cs.cs_error("CS_E_NO_ROWS")
cs.check_finite_columns(df, ["trial", "events_1", "total_1", "events_2", "total_2", "year"]) # infinite values stop the run (registry/errors.yaml)
# %% Studies
design = "binary" # inferred from the bound columns
measure = "RR"
cols = {
"events_1": df["events_1"].to_numpy(dtype=float),
"total_1": df["total_1"].to_numpy(dtype=float),
"events_2": df["events_2"].to_numpy(dtype=float),
"total_2": df["total_2"].to_numpy(dtype=float),
}
es = meta.escalc(design, measure, cols, zero_cells="only0", drop00=True, ci_level=0.95)
measure = es["measure"]
labels_all = df["trial"].astype(str).tolist()
keep = es["keep"]
left_out = [labels_all[i] for i in np.flatnonzero(~keep)]
idx = np.flatnonzero(keep)
y, v = es["yi"][idx], es["vi"][idx]
labels = [labels_all[i] for i in idx]
k = len(y)
if k < 2:
cs.cs_error("CS_E_TOO_FEW_ROWS", what="A meta-analysis", min=2, n=k) # one usable study can't be pooled
if left_out:
warnings.append(f"Left out ({len(left_out)}): " + ", ".join(left_out) + (" — no events (or only events) in both arms." if design == "binary" else " — effect or variance not computable."))
bt = meta.back_transform(measure)
MEASURE_LABEL = {"GEN": "effect", "LOG": "log ratio", "OR": "log odds ratio", "RR": "log risk ratio", "RD": "risk difference",
"MD": "mean difference", "SMD": "Hedges' g", "ZCOR": "Fisher's z", "COR": "correlation"}[measure]
RATIO = measure in ("OR", "RR", "LOG")
# What a back-transformed number is: a ratio, not a log ratio; a correlation, not Fisher's z.
DISPLAY_LABEL = {"OR": "odds ratio", "RR": "risk ratio", "LOG": "ratio", "ZCOR": "correlation"}.get(measure, MEASURE_LABEL)
if k < 3:
cs.cs_error("CS_E_TOO_FEW_ROWS", what="Leave-one-out influence", min=3, n=k) # each refit leaves out one study and needs two
# %% Influence
conf = 0.95
fit_method = "FE" if "random" == "fixed" else "REML"
test = "z"
inf = meta.influence(y, v, method=fit_method, test=test, level=conf)
full, rows = inf["full"], inf["rows"]
est = float(full["beta"][0])
rstud = np.array([r["rstudent"] for r in rows])
cooks = np.array([r["cooks"] for r in rows])
loo = np.array([r["est"] for r in rows])
top = int(np.argmax(cooks))
order = np.argsort(df["year"].to_numpy()[idx], kind="stable") # cumulative order: year
cum = meta.cumulative(y, v, order, method=fit_method, test=test, level=conf)
# %% Assumptions
assumptions = [{"key": "independence", "label": "Independent estimates", "status": "info", "detail": "One estimate per study is assumed."}]
# %% Result
disp = MEASURE_LABEL.replace("log ", "") if RATIO else MEASURE_LABEL
values = {"k": k, "est": est, "tau2": full["tau2"], "i2": full["i2"], "n_outlying": int(np.sum(np.abs(rstud) > 1.96)),
"max_abs_rstudent": float(np.max(np.abs(rstud))), "max_cooks": float(cooks[top]), "most_influential": labels[top],
"loo_min": float(loo.min()), "loo_max": float(loo.max()), "measure": measure, "measure_label": MEASURE_LABEL}
for i, r in enumerate(rows):
values[f"loo_est[{labels[i]}]"] = r["est"]; values[f"loo_tau2[{labels[i]}]"] = r["tau2"]; values[f"rstudent[{labels[i]}]"] = r["rstudent"]
values[f"cooks[{labels[i]}]"] = r["cooks"]; values[f"baujat_x[{labels[i]}]"] = r["baujat_x"]; values[f"baujat_y[{labels[i]}]"] = r["baujat_y"]
table_rows = [{"study": labels[i], "loo": float(bt(r["est"])), "low": float(bt(r["ci_low"])), "high": float(bt(r["ci_high"])), "tau2": r["tau2"], "i2": r["i2"],
"rstudent": r["rstudent"], "cooks": r["cooks"]} for i, r in enumerate(rows)]
charts = [
cs.chart("baujat", "baujat", "Contribution to heterogeneity against influence on the result",
{"x": cs.col("contribution to Q", [r["baujat_x"] for r in rows]), "y": cs.col("influence on the pooled estimate", [r["baujat_y"] for r in rows]),
"label": cs.col("study", labels)}),
cs.chart("influence", "influence-panel", "Leave-one-out diagnostics",
{"label": cs.col("study", labels), "rstudent": cs.col("studentized residual", [float(t) for t in rstud]), "cooks": cs.col("Cook's distance", [float(t) for t in cooks]),
"estimate": cs.col(disp + " without the study", [t["loo"] for t in table_rows]), "low": cs.col("low", [t["low"] for t in table_rows]),
"high": cs.col("high", [t["high"] for t in table_rows])},
controls={"pooled": float(bt(est)), "log": RATIO}),
]
cum_rows = []
if cum is not None:
for j, c in enumerate(cum):
values[f"cum_est[{labels[order[j]]}]"] = c["est"]
cum_rows.append({"study": "+ " + labels[order[j]], "estimate": float(bt(c["est"])), "low": float(bt(c["ci_low"])), "high": float(bt(c["ci_high"]))})
charts.append(cs.chart("cumulative", "cumulative-forest", "Cumulative meta-analysis",
{"label": cs.col("added study", [r["study"] for r in cum_rows]), "estimate": cs.col(disp, [r["estimate"] for r in cum_rows]),
"low": cs.col("low", [r["low"] for r in cum_rows]), "high": cs.col("high", [r["high"] for r in cum_rows])},
controls={"reference": 1 if RATIO else 0, "log": RATIO}))
cs.publish({
"method": "meta.influence",
"methodVersion": "1.0.1",
"title": f"Influence diagnostics for {k} studies",
"engine": cs.engine_info("numpy", "scipy"),
"n": k,
"summary": f"Without one study at a time the pooled {disp} ranges {bt(loo.min()):.3g} to {bt(loo.max()):.3g} (all studies {bt(est):.3g}); most influential: {labels[top]}.",
"statistics": [{"key": "max_cooks", "label": "Largest Cook's distance", "value": float(cooks[top])},
{"key": "n_outlying", "label": "Studies with |residual| > 1.96", "value": int(np.sum(np.abs(rstud) > 1.96)), "format": "integer"}],
"tables": [{"key": "loo", "title": f"Leave one out ({disp}, {conf:.0%} CI)",
"columns": [{"key": "study", "label": "Left out", "type": "string"}, {"key": "loo", "label": "Pooled", "type": "number"},
{"key": "low", "label": "CI low", "type": "number"}, {"key": "high", "label": "CI high", "type": "number"},
{"key": "tau2", "label": "τ²", "type": "number"}, {"key": "i2", "label": "I² (%)", "type": "number"},
{"key": "rstudent", "label": "Studentized residual", "type": "number"}, {"key": "cooks", "label": "Cook's distance", "type": "number"}],
"rows": table_rows}]
+ ([{"key": "cumulative", "title": "Cumulative pooled estimate", "columns": [{"key": "study", "label": "Study added", "type": "string"},
{"key": "estimate", "label": "Pooled", "type": "number"}, {"key": "low", "label": "CI low", "type": "number"}, {"key": "high", "label": "CI high", "type": "number"}],
"rows": cum_rows}] if cum_rows else []),
"assumptions": assumptions,
"warnings": warnings,
"notes": ["A study is worth a closer look when its studentized residual exceeds ±1.96 or its Cook's distance stands apart; never drop studies just to reduce heterogeneity."],
"charts": charts,
"values": values,
})
- Studentized deleted residuals: is this study surprising, given the others? The largest absolute value here is 1.45, and 0 studies are flagged as outlying.
- Cook's distance: how far does the whole fit move without it?
- Baujat plot: contribution to heterogeneity on one axis, influence on the result on the other. The top-right corner is the one to investigate.
What would you do with an outlier?
ReflectSay one trial dominates the Baujat plot. Removing it because it "looks wrong" is exactly the kind of choice that bends results.
Better: read that study's methods. Different population? Different dose? Then report the analysis with and without it, say why, and let the reader see both. What would you write in that paragraph?
Cumulative meta-analysis
ReadAdd the studies one at a time, in order of year, and pool after each. You see when the answer stabilized.
For BCG, order is set by the year column in the Order role. A cumulative plot can show that further trials added little, or that early large effects shrank over time.
It is descriptive. Repeated looks at accumulating data inflate false positives if you treat each step as a test, so don't read a "first significant year" as a discovery date.
Check your understanding
CheckpointCheck yourself
A leave-one-out analysis shows the pooled effect loses significance when one specific study is removed, while its size barely changes. What should you say?
Show the answer
Answer: b
Report size and interval rather than only crossing a threshold. A study's large weight can legitimately carry precision.
Check yourself
On a Baujat plot, which study should you look into first?
Show the answer
Answer: a
A study in the top-right corner both disagrees with the rest and changes the answer.
Check yourself
Read the influence panel for the BCG trials. What is the largest Cook's distance? Give two decimals.
Show the answer
Answer: 0.229481639115658
Cook's distance measures how far the whole fit moves without that study. It belongs to the most influential trial, which is worth reading in full before you decide anything.
Do it in CodeSplash
In the appThe Meta-analysis studio's Robustness step gathers leave-one-out, Baujat and cumulative views. The Multiverse tab there re-runs the analysis across reasonable choices of estimator and inclusion, so you see all the answers at once.
Recap
Recap- Leave-one-out shows how much rests on each study.
- Influence combines weight and distance; the Baujat plot shows both.
- Report analyses with and without influential studies, and read those studies' methods. Don't delete quietly.