Skip to content

The garden of forking paths

You can inflate false positives without running a single extra test, and without meaning to. See how many roads one dataset offers, and what each one does to the p-value.

Applied ~14 min9 steps

What runs in CodeSplash

You will be able to

  • Explain how analysis choices made after seeing the data inflate false positives
  • See how far several small choices move the false-positive rate
  • List the forks in an analysis of your own

Read first

01

A study of nothing

Predict

Predict first

Two groups, and no real difference between them. You measured three outcomes. You might also drop extreme values, look inside two subgroups, or add a few people if p is close. Any one result below 0.05 counts as a finding.

How often does a study of nothing end with a finding?

About 5%About 15%About 30%More than 60%
Reveal

About 30%, and the next step lets you check that. Each of those choices is one a careful person might make.

02

Walk the garden

Explore

Every simulated study here has no effect. Turn the choices on one at a time, and watch the false-positive rate climb away from 5%.

BExplorable · The garden of forking paths

How often does a study with no effect find p < .05 if the analysis is chosen after seeing the data?

With these choices, how often will a study of nothing find p < .05?

0.50
How sure?
3
30
Simulating…

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Each choice alone adds only a few points, and together they add up. Now switch everything off: one planned analysis keeps its promise. More data won't rescue you. Raise nn with the forks on, and the rate stays high.

03

One dataset, seven roads

Read

Here is the same thing in real data. ToothGrowth again: orange juice against ascorbic acid, the same 60 animals and the same column. You could defend every row.

RoadResult
Welch t testp = .061
Permutation testp = .066
Mann–Whitneyp = .064
Brunner–Munzelp = .063
20% trimmed means (Yuen)p = .029
Student's t, one-sided: "OJ is higher"p = .030
Two-way ANOVA, adding dosep < .001

Four roads end above 0.05, and three below.

Yuen's trimmed-means t-testRecorded · Python and R agreeRecorded 2026-11-25 · 17 values compared
R

t(33.49) = 2.29, p = .029

t
2.287
df
33.491
p
.029
Trimmed-mean difference (OJ − VC)
5.122
95% CI
[0.5687, 9.676]

Effect size

  • AKP robust d 0.6393

Plots

Trimmed-mean difference (95% CI)How large are several estimates, how precise, and which exclude the null?
View data
Difference in lenCI highEstimateCI low
5.1229.676OJ − VC0.5687

Assumptions

  • Design — Two independent groups (Yuen's test).
  • Enough values after trimming — 18 and 18 values remain after trimming 6 and 6 from each tail.

Descriptives (20% trimming)

SamplenTrimmed meanMeanMedianWinsorized SD
OJ3021.70620.66322.7004.816
VC3016.58316.96316.5005.451
  • Difference = OJ − VC; 20% trimmed from each tail; alternative: two-sided.
The exact R script · R R version 4.5.1 (2025-06-13)
# Yuen's trimmed-means t-test (independent or paired)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method robust.yuen 1.1.1 · spec b068cc1a7845e371
# Dataset: toothgrowth (version 1)
# Runs on its own: outside the app, cs_publish() writes $CS_RESULT_PATH or prints the result JSON.

# %% Setup
library(codesplashr)

# %% Data
df <- as.data.frame(nanoparquet::read_parquet("tests/parity/fixtures/toothgrowth.parquet", col_select = c("len", "supp")))
n_input <- nrow(df)
df[["supp"]] <- factor(df[["supp"]], levels = c("OJ", "VC"))  # stored level order
df <- df[stats::complete.cases(df[c("len", "supp")]), , 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("len", "supp"))  # infinite values stop the run (registry/errors.yaml)

# %% Two samples (independent groups or paired measurements, from the bound roles)
y <- "len"
g <- "supp"
levels_g <- levels(df[[g]])
if (length(levels_g) != 2) cs_error("CS_E_GROUP_COUNT", column = g, expected = 2, k = length(levels_g))
x1 <- df[[y]][df[[g]] == levels_g[1]]
x2 <- df[[y]][df[[g]] == levels_g[2]]
design <- "independent"
label_1 <- levels_g[1]
label_2 <- levels_g[2]

# %% Test
trim <- 0.2
conf <- 0.95
alternative <- "two-sided"
n1 <- length(x1)
n2 <- length(x2)
g1 <- floor(trim * n1)
g2 <- floor(trim * n2)
for (i in 1:2) {
  lab <- c(label_1, label_2)[i]
  if (c(n1, n2)[i] < 2) cs_error("CS_E_SMALL_GROUP", min = 2, group = if (design == "independent") paste0(g, " = ", lab) else lab, n = c(n1, n2)[i])
}
if (n1 - 2 * g1 < 2 || n2 - 2 * g2 < 2) {
  cs_error("CS_E_UNDEFINED", what = "Yuen's test", reason = "each sample needs at least two values left after trimming")
}
if (design == "independent") {
  if (length(unique(c(x1, x2))) < 2) cs_error("CS_E_CONSTANT", column = y)  # no variation: the standard error is 0
  if (diff(range(cs_winsorize(x1, trim))) == 0 && diff(range(cs_winsorize(x2, trim))) == 0) {
    cs_error("CS_E_UNDEFINED", what = "Yuen's test", reason = "neither group has any spread left after Winsorizing")
  }
} else if (all(x1 == x2)) {
  cs_error("CS_E_ALL_ZERO_DIFFERENCES")
}
if (design == "independent") {
  r <- cs_yuen(x1, x2, trim, conf, alternative)  # WRS2::yuen
  akp <- r$akp
} else {
  r <- cs_yuend(x1, x2, trim, conf, alternative)  # WRS2::yuend
  akp <- NULL
}

# Lens (equivalence / minimal effect / non-inferiority) on the trimmed-mean difference, at alpha = 1 - confidence.
lens_kind <- "none"
lens <- NULL
if (lens_kind != "none") lens <- cs_lens(lens_kind, r$diff, r$se, r$df, NULL, NULL, 1 - conf)

# %% Assumptions
assumptions <- list(
  list(key = "design", label = "Design", status = "info",
       detail = if (design == "independent") "Two independent groups (Yuen's test)." else "Paired measurements on the same rows (Yuen's paired test)."),
  list(key = "sample_size", label = "Enough values after trimming", status = if (min(n1 - 2 * g1, n2 - 2 * g2) < 5) "warn" else "pass",
       detail = sprintf("%d and %d values remain after trimming %d and %d from each tail.", n1 - 2 * g1, n2 - 2 * g2, g1, g2))
)

# %% Result
values <- list(t = r$t, df = r$df, p = r$p, diff = r$diff, se = r$se, ci_low = r$ci_low, ci_high = r$ci_high,
               tm_1 = r$tm_1, tm_2 = r$tm_2, n_1 = n1, n_2 = n2, trim = trim, akp = akp, design = design,
               label_1 = label_1, label_2 = label_2)
if (!is.null(lens)) values <- c(values, lens)
effects <- if (!is.null(akp)) list(list(key = "akp", label = "AKP robust d", value = akp, method = "0.642 × Δ_t / pooled winsorized SD (Algina et al. 2005)")) else list()
descr <- data.frame(sample = c(label_1, label_2), n = c(n1, n2), trimmed_mean = c(cs_trim_mean(x1, trim), cs_trim_mean(x2, trim)),
                    mean = c(mean(x1), mean(x2)), median = c(median(x1), median(x2)),
                    win_sd = c(sd(cs_winsorize(x1, trim)), sd(cs_winsorize(x2, trim))), stringsAsFactors = FALSE)
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0  # consult-a-statistician input
pct <- sprintf("%.0f%%", conf * 100)
cs_publish(list(
  method = "robust.yuen",
  methodVersion = "1.1.1",
  title = paste0("Yuen's trimmed-means t-test", if (design == "paired") " (paired)" else ""),
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n1 + if (design == "independent") n2 else 0,
  summary = paste0(sprintf("Trimmed means %.2f vs %.2f: difference %.2f, %s.", r$tm_1, r$tm_2, r$diff, cs_fmt_p(r$p)),
                   if (!is.null(lens)) sprintf(" Lens (%s): %s (%s).", gsub("_", " ", lens_kind), lens$lens_verdict, cs_fmt_p(lens$lens_p)) else ""),
  apa = sprintf("t(%s) = %s, %s", cs_fmt_num(r$df), cs_fmt_num(r$t), cs_fmt_p(r$p)),
  statistics = c(list(list(key = "t", label = "t", value = r$t), list(key = "df", label = "df", value = r$df),
                    list(key = "p", label = "p", value = r$p, format = "p"),
                    list(key = "diff", label = sprintf("Trimmed-mean difference (%s − %s)", label_1, label_2), value = r$diff),
                    list(key = "ci", label = paste(pct, "CI"), value = c(r$ci_low, r$ci_high))),
                 if (!is.null(lens)) list(list(key = "lens_p", label = sprintf("Lens p (%s)", gsub("_", " ", lens_kind)), value = lens$lens_p, format = "p")) else list()),
  tables = list(list(key = "descriptives", title = sprintf("Descriptives (%.0f%% trimming)", trim * 100),
                     columns = list(list(key = "sample", label = "Sample", type = "string"), list(key = "n", label = "n", type = "integer"),
                                    list(key = "trimmed_mean", label = "Trimmed mean", type = "number"), list(key = "mean", label = "Mean", type = "number"),
                                    list(key = "median", label = "Median", type = "number"), list(key = "win_sd", label = "Winsorized SD", type = "number")),
                     rows = descr)),
  effectSizes = effects,
  assumptions = assumptions,
  warnings = warnings,
  notes = c(list(sprintf("Difference = %s − %s; %.0f%% trimmed from each tail; alternative: %s.", label_1, label_2, trim * 100, alternative)),
            if (!is.null(lens)) list(sprintf("The lens interval [%.3g, %.3g] is the %.0f%% interval for the trimmed-mean difference.", lens$lens_ci_low, lens$lens_ci_high, (1 - 2 * (1 - conf)) * 100)) else list()),
  values = values,
  charts = list(cs_chart("estimate", "forest", sprintf("Trimmed-mean difference (%s CI)", pct), list(
    label = cs_col("Estimate", sprintf("%s − %s", label_1, label_2), "categorical"),
    estimate = cs_col(sprintf("Difference in %s", y), r$diff, "numeric"),
    low = cs_col("CI low", r$ci_low, "numeric"), high = cs_col("CI high", r$ci_high, "numeric")), controls = list(reference = 0)))
))
Python

t(33.49) = 2.29, p = .029

t
2.287
df
33.491
p
.029
Trimmed-mean difference (OJ − VC)
5.122
95% CI
[0.5687, 9.676]

Effect size

  • AKP robust d 0.6393

To keep this page light, the plots are shown once, under the R tab.

Assumptions

  • Design — Two independent groups (Yuen's test).
  • Enough values after trimming — 18 and 18 values remain after trimming 6 and 6 from each tail.

Descriptives (20% trimming)

SamplenTrimmed meanMeanMedianWinsorized SD
OJ3021.70620.66322.7004.816
VC3016.58316.96316.5005.451
  • Difference = OJ − VC; 20% trimmed from each tail; alternative: two-sided.
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Yuen's trimmed-means t-test (independent or paired)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method robust.yuen 1.1.1 · spec b068cc1a7845e371
# Dataset: toothgrowth (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 means as csm
from codesplash.stats import robust

# %% Data
df = pd.read_parquet("tests/parity/fixtures/toothgrowth.parquet", columns=["len", "supp"])
n_input = len(df)
df["supp"] = pd.Categorical(df["supp"], categories=["OJ", "VC"])  # stored level order
df = df.dropna(subset=["len", "supp"])  # listwise deletion over the analysis columns
df["supp"] = df["supp"].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, ["len", "supp"])  # infinite values stop the run (registry/errors.yaml)

# %% Two samples (independent groups or paired measurements, from the bound roles)
y = "len"
g = "supp"
levels = [str(x) for x in df[g].cat.categories]
if len(levels) != 2:
    cs.cs_error("CS_E_GROUP_COUNT", column=g, expected=2, k=len(levels))
x1 = df.loc[df[g] == df[g].cat.categories[0], y].to_numpy(dtype=float)
x2 = df.loc[df[g] == df[g].cat.categories[1], y].to_numpy(dtype=float)
design, label_1, label_2 = "independent", levels[0], levels[1]

# %% Test
trim = 0.2
conf = 0.95
alternative = "two-sided"
n1, n2 = len(x1), len(x2)
g1, g2 = int(np.floor(trim * n1)), int(np.floor(trim * n2))
for lab, n_s in ((label_1, n1), (label_2, n2)):
    if n_s < 2:
        cs.cs_error("CS_E_SMALL_GROUP", min=2, group=f"{g} = {lab}" if design == "independent" else lab, n=n_s)
if n1 - 2 * g1 < 2 or n2 - 2 * g2 < 2:
    cs.cs_error("CS_E_UNDEFINED", what="Yuen's test", reason="each sample needs at least two values left after trimming")
if design == "independent":
    if len(np.unique(np.concatenate([x1, x2]))) < 2:  # no variation: the standard error is 0
        cs.cs_error("CS_E_CONSTANT", column=y)
    if np.ptp(robust.winsorize(x1, trim)) == 0 and np.ptp(robust.winsorize(x2, trim)) == 0:
        cs.cs_error("CS_E_UNDEFINED", what="Yuen's test", reason="neither group has any spread left after Winsorizing")
elif np.all(x1 == x2):
    cs.cs_error("CS_E_ALL_ZERO_DIFFERENCES")
if design == "independent":
    r = robust.yuen(x1, x2, trim, conf, alternative)  # WRS2::yuen (= scipy ttest_ind(trim=, equal_var=False))
    akp = r["akp"]
else:
    r = robust.yuend(x1, x2, trim, conf, alternative)  # WRS2::yuend
    akp = None

# Lens (equivalence / minimal effect / non-inferiority) on the trimmed-mean difference, at α = 1 − confidence.
lens_kind = "none"
lens = None
if lens_kind != "none":
    lens = csm.lens(lens_kind, r["diff"], r["se"], r["df"], None, None, 1 - conf)

# %% Assumptions
assumptions = [
    {"key": "design", "label": "Design", "status": "info",
     "detail": "Two independent groups (Yuen's test)." if design == "independent" else "Paired measurements on the same rows (Yuen's paired test)."},
    {"key": "sample_size", "label": "Enough values after trimming", "status": "warn" if min(n1 - 2 * g1, n2 - 2 * g2) < 5 else "pass",
     "detail": f"{n1 - 2 * g1} and {n2 - 2 * g2} values remain after trimming {g1} and {g2} from each tail."},
]

# %% Result
values = {"t": r["t"], "df": r["df"], "p": r["p"], "diff": r["diff"], "se": r["se"], "ci_low": r["ci_low"], "ci_high": r["ci_high"],
          "tm_1": r["tm_1"], "tm_2": r["tm_2"], "n_1": n1, "n_2": n2, "trim": trim, "akp": akp, "design": design,
          "label_1": label_1, "label_2": label_2, **(lens or {})}
effects = [{"key": "akp", "label": "AKP robust d", "value": akp, "method": "0.642 × Δ_t / pooled winsorized SD (Algina et al. 2005)"}] if akp is not None else []
descr = [{"sample": lab, "n": len(x), "trimmed_mean": robust.trim_mean(x, trim), "mean": float(np.mean(x)), "median": float(np.median(x)),
          "win_sd": float(np.std(robust.winsorize(x, trim), ddof=1))} for lab, x in ((label_1, x1), (label_2, x2))]
values["missing_share"] = n_dropped / n_input if n_input else 0.0  # consult-a-statistician input
cs.publish({
    "method": "robust.yuen",
    "methodVersion": "1.1.1",
    "title": "Yuen's trimmed-means t-test" + (" (paired)" if design == "paired" else ""),
    "engine": cs.engine_info("pandas", "numpy", "scipy"),
    "n": n1 + (n2 if design == "independent" else 0),
    "summary": f"Trimmed means {r['tm_1']:.2f} vs {r['tm_2']:.2f}: difference {r['diff']:.2f}, {cs.fmt_p(r['p'])}."
               + (f" Lens ({lens_kind.replace('_', ' ')}): {lens['lens_verdict']} ({cs.fmt_p(lens['lens_p'])})." if lens else ""),
    "apa": f"t({cs.fmt_num(r['df'])}) = {cs.fmt_num(r['t'])}, {cs.fmt_p(r['p'])}",
    "statistics": [{"key": "t", "label": "t", "value": r["t"]}, {"key": "df", "label": "df", "value": r["df"]},
                   {"key": "p", "label": "p", "value": r["p"], "format": "p"},
                   {"key": "diff", "label": f"Trimmed-mean difference ({label_1} − {label_2})", "value": r["diff"]},
                   {"key": "ci", "label": f"{conf:.0%} CI", "value": [r["ci_low"], r["ci_high"]]}]
                  + ([{"key": "lens_p", "label": f"Lens p ({lens_kind.replace('_', ' ')})", "value": lens["lens_p"], "format": "p"}] if lens else []),
    "tables": [{"key": "descriptives", "title": f"Descriptives ({trim:.0%} trimming)", "columns": [
        {"key": "sample", "label": "Sample", "type": "string"}, {"key": "n", "label": "n", "type": "integer"},
        {"key": "trimmed_mean", "label": "Trimmed mean", "type": "number"}, {"key": "mean", "label": "Mean", "type": "number"},
        {"key": "median", "label": "Median", "type": "number"}, {"key": "win_sd", "label": "Winsorized SD", "type": "number"}], "rows": descr}],
    "effectSizes": effects,
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"Difference = {label_1} − {label_2}; {trim:.0%} trimmed from each tail; alternative: {alternative}."]
             + ([f"The lens interval [{lens['lens_ci_low']:.3g}, {lens['lens_ci_high']:.3g}] is the {1 - 2 * (1 - conf):.0%} interval for the trimmed-mean difference."] if lens else []),
    "values": values,
    "charts": [cs.chart("estimate", "forest", f"Trimmed-mean difference ({conf:.0%} CI)", {
        "label": cs.col("Estimate", [f"{label_1} − {label_2}"], "categorical"),
        "estimate": cs.col(f"Difference in {y}", [r["diff"]], "numeric"),
        "low": cs.col("CI low", [r["ci_low"]], "numeric"), "high": cs.col("CI high", [r["ci_high"]], "numeric")}, controls={"reference": 0})],
})
04

Which road is right?

Predict

Predict first

Which of those seven results should you report?

Yuen: it's significant and robustStudent's one-sided: OJ was expected to winWelch: it's the defaultYou can't tell from the p-values
Reveal

You can't tell from the p-values, and that's the point. The choice has to come from the question and the design. Dose was part of this experiment, so the two-way ANOVA has a strong claim, and you could have said so before seeing a number. Picking it because its p is smallest would give the same output, and mean something else.

05

Nobody has to cheat

Read

Gelman and Loken called this the garden of forking pathsGarden of forking pathsMany reasonable analysis choices made after seeing the data inflate false positives even without intent.. You run one test and report it faithfully. But had the data looked different, you would have cleaned them differently, or looked at another subgroup.

A p-value assumes the analysis would have been the same whatever the data showed. That is the assumption that fails. So the question isn't "how many tests did I run?" It's "how many would I have run, if the data had come out differently?"

06

Name your forks

Reflect

Pick an analysis you did recently. For each of these, write down whether you decided before or after seeing results:

  • Which outcome, and how it was defined
  • Which rows were excluded, and by what rule
  • Which covariates went in
  • Which transformation and which test
  • Which subgroups you looked at
  • When you stopped collecting data

Every "after" is a fork. That doesn't make the result wrong. It makes it exploratory, and your reader needs to know.

07

Check your understanding

Checkpoint

Check yourself

An analyst plots the data, sees that one subgroup stands out, and runs a single t test on that subgroup. It gives p = .02. What does that p-value mean here?

Show the answer

Answer: b

The data chose the test. There's no simple correction, because the number of tests that could have been run isn't known. Treat it as a lead to test in new data.

Check yourself

You have five independent ways to analyze a study with no real effect, and you'll report any that reaches p ≤ .05. What is the chance of at least one? Give two decimals or more.

Show the answer

Answer: 0.2262

1−0.955≈0.2261 - 0.95^5 \approx 0.226. Real forks overlap, because they reuse the same data, so the true figure is lower. It's still far above 5%.

Check yourself

A colleague says their forks don't matter because nn = 50,000. What should you say?

Show the answer

Answer: c

A larger sample shrinks random error, and a true null still gives p≤0.05p \le 0.05 in 5% of analyses at any size. Each extra road is another 5% draw.

08

Try it yourself

In the app

Run the Welch test, then rerun it with Alternative hypothesis set to one side and look at p. Open Multiple testing in the Analyze rail, then the dataset's family: the earlier run is still there, under Earlier runs. Keep that in mind for later lessons, where the ledger and the specification curve turn these forks into something you can report.

Python
import numpy as np
from scipy import stats

rng = np.random.default_rng(1)
n, reps, hits = 30, 2000, 0
for _ in range(reps):
    # Three correlated outcomes; the two groups differ in nothing.
    shared = rng.normal(size=(2 * n, 1))
    y = np.sqrt(0.5) * shared + np.sqrt(0.5) * rng.normal(size=(2 * n, 3))
    ps = [stats.ttest_ind(y[:n, j], y[n:, j], equal_var=False).pvalue for j in range(3)]
    hits += min(ps) <= 0.05
print(hits / reps)  # one outcome chosen in advance would give about 0.05
R
set.seed(1)
n <- 30; reps <- 2000
hit <- replicate(reps, {
  # Three correlated outcomes; the two groups differ in nothing.
  shared <- rnorm(2 * n)
  y <- sqrt(0.5) * shared + sqrt(0.5) * matrix(rnorm(6 * n), ncol = 3)
  ps <- apply(y, 2, function(v) t.test(v[1:n], v[(n + 1):(2 * n)])$p.value)
  min(ps) <= 0.05
})
mean(hit)  # one outcome chosen in advance would give about 0.05

These scripts use each language's own random generator, so their results differ slightly.

09

Recap

Recap
  • A flexible analysis of nothing finds something far more often than 5% of the time, with no bad intent.
  • A p-value assumes the analysis would have been the same whatever the data showed.
  • Ask how many analyses you would have run, not how many you did. Choices made after seeing results make a finding exploratory, so say so.

Concepts in this lesson