Putting studies on one scale
Turn counts, means, correlations and published ratios into comparable effect sizes with their variances, and handle zero cells deliberately.
What runs in CodeSplash
- Effect sizes for meta-analysis Verified in Python and R
You will be able to
- Choose an effect measure that suits what the studies report
- Explain why ratios and correlations are pooled on a transformed scale
- Say what a zero-cell correction does and when a double-zero study is left out
Read first
Studies rarely report the same thing
ReadOne trial gives event counts. Another gives means and SDs. A third prints an odds ratio with a confidence interval. Pooling needs every study on one scale, each with a sampling variance.
CodeSplash detects the design from your columns:
| You have | Design | Usual measure |
|---|---|---|
| Events and totals per arm | Two-arm counts | Log odds or risk ratio |
| Mean, SD and n per arm | Means and SDs | Effect sizeEffect sizeHow large a difference or relationship is, in units you can interpret. as Hedges' g |
| r and n | Correlations | Fisher's z |
| Ratio with CI limits | Ratio with CI | Log ratio |
| Estimate and SE | Estimate and SE | As given |
Why transform?
PredictPredict first
Two equally precise trials report risk ratios of 2 and 0.5: one doubles the risk, the other halves it. They should cancel out.
Average the ratios directly. What do you get?
Reveal
, above 1, even though the trials are mirror images. On the log scale, and are exact opposites and average to 0, which turns back into a ratio of 1. That is why ratios are pooled as logs.
Four designs, four outputs
ReadThe same machinery handles each design:
- BCG trials as log risk ratios: 13 studies, median variance 0.070.
- Stroke-unit trials as Hedges' g: 9 studies, mean g −0.55.
- Conscientiousness and adherence as correlations: 16 studies.
- Passive smoking from published ratios with CIs: 37 studies.
9 studies on the Hedges' g scale.
- Studies
- 9
- Unweighted mean Hedges' g
- −0.5537
Plots
View data
| Hedges' g | high | study | low | inverse variance |
|---|---|---|---|---|
| −0.3552 | −0.1311 | Edinburgh | −0.5792 | 76.542 |
| −0.3479 | 0.1497 | Orpington-Mild | −0.8456 | 15.511 |
| −2.318 | −1.898 | Orpington-Moderate | −2.737 | 21.828 |
| −1.888 | −1.102 | Orpington-Severe | −2.673 | 6.226 |
| −0.3840 | 0.5044 | Montreal-Home | −1.272 | 4.868 |
| 0.1721 | 0.5487 | Montreal-Transfer | −0.2044 | 27.093 |
| 0.2721 | 0.7532 | Newcastle | −0.2091 | 16.593 |
| −0.4246 | −0.1856 | Umea | −0.6635 | 67.281 |
| 0.2896 | 0.6628 | Uppsala | −0.0837 | 27.570 |
Assumptions
- Same scale — Effects are on the Hedges' g scale.
Effect sizes (Hedges' g; 95% CI shown as Hedges' g)
| Study | yi | vi | SE | Hedges' g | CI low | CI high |
|---|---|---|---|---|---|---|
| Edinburgh | −0.3552 | 0.0131 | 0.1143 | −0.3552 | −0.5792 | −0.1311 |
| Orpington-Mild | −0.3479 | 0.0645 | 0.2539 | −0.3479 | −0.8456 | 0.1497 |
| Orpington-Moderate | −2.318 | 0.0458 | 0.2140 | −2.318 | −2.737 | −1.898 |
| Orpington-Severe | −1.888 | 0.1606 | 0.4008 | −1.888 | −2.673 | −1.102 |
| Montreal-Home | −0.3840 | 0.2054 | 0.4532 | −0.3840 | −1.272 | 0.5044 |
| Montreal-Transfer | 0.1721 | 0.0369 | 0.1921 | 0.1721 | −0.2044 | 0.5487 |
| Newcastle | 0.2721 | 0.0603 | 0.2455 | 0.2721 | −0.2091 | 0.7532 |
| Umea | −0.4246 | 0.0149 | 0.1219 | −0.4246 | −0.6635 | −0.1856 |
| Uppsala | 0.2896 | 0.0363 | 0.1905 | 0.2896 | −0.0837 | 0.6628 |
The exact R script · R R version 4.5.1 (2025-06-13)
# Effect sizes for meta-analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method meta.escalc 1.0.1 · spec a69919bc2b61aa5b
# Dataset: m1_normand (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_normand.parquet", col_select = c("source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2")))
n_input <- nrow(df)
df[["source"]] <- factor(df[["source"]], levels = c("Edinburgh", "Orpington-Mild", "Orpington-Moderate", "Orpington-Severe", "Montreal-Home", "Montreal-Transfer", "Newcastle", "Umea", "Uppsala")) # stored level order
df <- df[stats::complete.cases(df[c("source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2")]), , 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("source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2")) # infinite values stop the run (registry/errors.yaml)
# %% Studies
design <- "means" # inferred from the bound columns
measure <- "SMD"
cols <- list(
total_1 = as.numeric(df[["total_1"]]),
total_2 = as.numeric(df[["total_2"]]),
mean_1 = as.numeric(df[["mean_1"]]),
sd_1 = as.numeric(df[["sd_1"]]),
mean_2 = as.numeric(df[["mean_2"]]),
sd_2 = as.numeric(df[["sd_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[["source"]])
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
# %% Result
conf <- 0.95
zc <- stats::qnorm(1 - (1 - conf) / 2)
se <- sqrt(v)
lo <- y - zc * se; hi <- y + zc * se
disp <- if (RATIO) sub("log ", "", MEASURE_LABEL) else MEASURE_LABEL
rows <- lapply(seq_len(k), function(i) list(study = labels[i], yi = y[i], vi = v[i], se = se[i], estimate = bt(y[i]), low = bt(lo[i]), high = bt(hi[i])))
values <- list(k = k, k_left_out = length(left_out), measure = measure, measure_label = MEASURE_LABEL, yi_mean = mean(y), vi_median = stats::median(v))
for (i in seq_len(k)) {
values[[sprintf("yi[%s]", labels[i])]] <- y[i]
values[[sprintf("vi[%s]", labels[i])]] <- v[i]
}
cs_publish(list(
method = "meta.escalc",
methodVersion = "1.0.1",
title = sprintf("Effect sizes: %s for %d studies", MEASURE_LABEL, k),
engine = cs_engine_info("stats", "nanoparquet"),
n = k,
summary = paste0(sprintf("%d studies on the %s scale", k, MEASURE_LABEL), if (length(left_out)) sprintf("; %d left out", length(left_out)) else "", "."),
statistics = list(list(key = "k", label = "Studies", value = k, format = "integer"),
list(key = "yi_mean", label = paste("Unweighted mean", MEASURE_LABEL), value = mean(y))),
tables = list(list(key = "effects", title = sprintf("Effect sizes (%s; %.0f%% CI shown as %s)", MEASURE_LABEL, conf * 100, disp),
columns = list(list(key = "study", label = "Study", type = "string"), list(key = "yi", label = "yi", type = "number"),
list(key = "vi", label = "vi", type = "number"), list(key = "se", label = "SE", type = "number"),
list(key = "estimate", label = disp, type = "number"), list(key = "low", label = "CI low", type = "number"),
list(key = "high", label = "CI high", type = "number")),
rows = rows)),
assumptions = list(list(key = "scale", label = "Same scale", status = if (measure == "MD") "warn" else "pass",
detail = if (measure == "MD") "Mean differences assume every study used the same measurement scale." else sprintf("Effects are on the %s scale.", MEASURE_LABEL))),
warnings = warnings,
notes = if (RATIO) list("Ratios are analyzed on the log scale; the table shows them back-transformed.") else list(),
charts = list(cs_chart("effects", "forest-meta", "Study effect sizes",
list(label = cs_col("study", labels), estimate = cs_col(disp, bt(y)), low = cs_col("low", bt(lo)), high = cs_col("high", bt(hi)),
weight = cs_col("inverse variance", 1 / v)),
controls = list(reference = if (RATIO) 1 else 0, log = RATIO))),
values = values
))
9 studies on the Hedges' g scale.
- Studies
- 9
- Unweighted mean Hedges' g
- −0.5537
To keep this page light, the plots are shown once, under the R tab.
Assumptions
- Same scale — Effects are on the Hedges' g scale.
Effect sizes (Hedges' g; 95% CI shown as Hedges' g)
| Study | yi | vi | SE | Hedges' g | CI low | CI high |
|---|---|---|---|---|---|---|
| Edinburgh | −0.3552 | 0.0131 | 0.1143 | −0.3552 | −0.5792 | −0.1311 |
| Orpington-Mild | −0.3479 | 0.0645 | 0.2539 | −0.3479 | −0.8456 | 0.1497 |
| Orpington-Moderate | −2.318 | 0.0458 | 0.2140 | −2.318 | −2.737 | −1.898 |
| Orpington-Severe | −1.888 | 0.1606 | 0.4008 | −1.888 | −2.673 | −1.102 |
| Montreal-Home | −0.3840 | 0.2054 | 0.4532 | −0.3840 | −1.272 | 0.5044 |
| Montreal-Transfer | 0.1721 | 0.0369 | 0.1921 | 0.1721 | −0.2044 | 0.5487 |
| Newcastle | 0.2721 | 0.0603 | 0.2455 | 0.2721 | −0.2091 | 0.7532 |
| Umea | −0.4246 | 0.0149 | 0.1219 | −0.4246 | −0.6635 | −0.1856 |
| Uppsala | 0.2896 | 0.0363 | 0.1905 | 0.2896 | −0.0837 | 0.6628 |
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Effect sizes for meta-analysis
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method meta.escalc 1.0.1 · spec a69919bc2b61aa5b
# Dataset: m1_normand (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
from scipy import stats
import codesplash as cs
from codesplash.stats import meta # twins of codesplashr::cs_meta_*
# %% Data
df = pd.read_parquet("tests/parity/fixtures/m1_normand.parquet", columns=["source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2"])
n_input = len(df)
df["source"] = pd.Categorical(df["source"], categories=["Edinburgh", "Orpington-Mild", "Orpington-Moderate", "Orpington-Severe", "Montreal-Home", "Montreal-Transfer", "Newcastle", "Umea", "Uppsala"]) # stored level order
df = df.dropna(subset=["source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2"]) # listwise deletion over the analysis columns
df["source"] = df["source"].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, ["source", "total_1", "total_2", "mean_1", "sd_1", "mean_2", "sd_2"]) # infinite values stop the run (registry/errors.yaml)
# %% Studies
design = "means" # inferred from the bound columns
measure = "SMD"
cols = {
"total_1": df["total_1"].to_numpy(dtype=float),
"total_2": df["total_2"].to_numpy(dtype=float),
"mean_1": df["mean_1"].to_numpy(dtype=float),
"sd_1": df["sd_1"].to_numpy(dtype=float),
"mean_2": df["mean_2"].to_numpy(dtype=float),
"sd_2": df["sd_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["source"].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)
# %% Result
conf = 0.95
zc = float(stats.norm.ppf(1 - (1 - conf) / 2))
se = np.sqrt(v)
lo, hi = y - zc * se, y + zc * se
disp = MEASURE_LABEL.replace("log ", "") if RATIO else MEASURE_LABEL
rows = [{"study": labels[i], "yi": float(y[i]), "vi": float(v[i]), "se": float(se[i]), "estimate": float(bt(y[i])),
"low": float(bt(lo[i])), "high": float(bt(hi[i]))} for i in range(k)]
values = {"k": k, "k_left_out": len(left_out), "measure": measure, "measure_label": MEASURE_LABEL,
"yi_mean": float(np.mean(y)), "vi_median": float(np.median(v))}
for i in range(k):
values[f"yi[{labels[i]}]"] = float(y[i])
values[f"vi[{labels[i]}]"] = float(v[i])
cs.publish({
"method": "meta.escalc",
"methodVersion": "1.0.1",
"title": f"Effect sizes: {MEASURE_LABEL} for {k} studies",
"engine": cs.engine_info("numpy", "scipy"),
"n": k,
"summary": f"{k} studies on the {MEASURE_LABEL} scale" + (f"; {len(left_out)} left out" if left_out else "") + ".",
"statistics": [{"key": "k", "label": "Studies", "value": k, "format": "integer"},
{"key": "yi_mean", "label": f"Unweighted mean {MEASURE_LABEL}", "value": float(np.mean(y))}],
"tables": [{"key": "effects", "title": f"Effect sizes ({MEASURE_LABEL}; {conf:.0%} CI shown as {disp})",
"columns": [{"key": "study", "label": "Study", "type": "string"}, {"key": "yi", "label": "yi", "type": "number"},
{"key": "vi", "label": "vi", "type": "number"}, {"key": "se", "label": "SE", "type": "number"},
{"key": "estimate", "label": disp, "type": "number"}, {"key": "low", "label": "CI low", "type": "number"},
{"key": "high", "label": "CI high", "type": "number"}],
"rows": rows}],
"assumptions": [{"key": "scale", "label": "Same scale", "status": "warn" if measure == "MD" else "pass",
"detail": "Mean differences assume every study used the same measurement scale." if measure == "MD" else f"Effects are on the {MEASURE_LABEL} scale."}],
"warnings": warnings,
"notes": ["Ratios are analyzed on the log scale; the table shows them back-transformed."] if RATIO else [],
"charts": [cs.chart("effects", "forest-meta", "Study effect sizes",
{"label": cs.col("study", labels), "estimate": cs.col(disp, [r["estimate"] for r in rows]),
"low": cs.col("low", [r["low"] for r in rows]), "high": cs.col("high", [r["high"] for r in rows]),
"weight": cs.col("inverse variance", [float(t) for t in 1 / v])},
controls={"reference": 1 if RATIO else 0, "log": RATIO})],
"values": values,
})
Standardized or not?
ReflectHedges' g divides a mean difference by the pooled SD, so studies using different instruments become comparable. But if every study measured length of stay in days, a raw mean difference in days is easier to act on.
For your own data: would a decision-maker rather hear "0.5 SD shorter" or "2 days shorter"? Decide before you choose the measure, not after you see which one looks stronger.
Zero cells
ReadA trial with no events in one arm has an undefined log ratio. CodeSplash's Zero cells option says what to do:
- Add ½ to studies with a zero cell (the default).
- Add ½ to every study.
- No correction, which drops undefined studies.
Studies with no events in either arm carry no information about a ratio, so Leave out double-zero studies is on by default. The card reports how many were left out.
Check your understanding
CheckpointCheck yourself
Your studies report correlations between the same two constructs, with sample sizes. What does CodeSplash pool, and why?
Show the answer
Answer: a
Fisher's z stabilizes the variance at about . The pooled z is turned back into r for reporting.
Check yourself
A study reports a correlation with . Its Fisher's z has variance . What is that variance?
Show the answer
Answer: 0.01
.
Check yourself
A trial had no events in either arm. For a risk ratio, what does CodeSplash do by default?
Show the answer
Answer: b
Double-zero studies are left out by default for ratios. The Leave out double-zero studies option controls this, and the card reports the count.
Do it on your own table
In the appCompute effect sizes first and look at them before pooling anything. An impossible value here usually means a typo in a study's row.
Recap
Recap- Every study needs an effect on one scale and a sampling variance.
- Ratios are pooled as logs and correlations as Fisher's z, then turned back.
- Zero-cell handling is a choice; the card states what happened.
Concepts in this lesson