Skip to content

A reproducible analysis record

Could someone rerun your analysis and get the same numbers? See what CodeSplash already records for you, and what only you can add.

Applied ~10 min8 steps

What runs in CodeSplash

You will be able to

  • List what someone needs to reproduce a result
  • Find a run's dataset version, method version, code and engine agreement
  • Export an analysis package and verify it
01

What "reproducible" needs

Read

A result can be reproduced when someone else can get the same numbers, and can see every choice that led to them. That takes six things:

  1. The exact data, not "the latest file"
  2. Every preparation step
  3. The method and its options
  4. The software versions
  5. The random seedRandom seedThe starting point of a random-number stream; the same seed reproduces the same resamples., if anything was random
  6. Why you made the choices you made

CodeSplash records the first five as you work. The sixth is yours.

02

Where each one lives

Read
You needWhere to find it
DataDataset versions: every import and saved recipe is a new version
PreparationThe recipe, with an export to SQL, pandas and dplyr
Method and optionsThe setup panel, and the header of the generated code
VersionsThe header of the generated code, and the environment locks in a package
SeedThe Seed field in the setup panel, on methods that draw random numbers

The header of generated code names the method version, a hash of the spec, and the dataset version. Change any of them, and the hash shows that it isn't the same analysis.

03

Same seed, same answer

Predict

Predict first

A permutation test used 1,999 shuffles and found p = .066 in Python. You run it again in R with the same seed. What happens?

The same pA slightly different pVery different p
Reveal

The same p, down to the count: 130 shuffles at least as extreme. CodeSplash's Python and R helpers draw from one shared random generator, so the same seed gives the same shuffles. A different seed gives a slightly different p, which is the Monte Carlo error you should expect.

04

Two engines as a check

Read
Permutation testRecorded · Python and R agreeRecorded 2026-11-25 · 13 values compared
R

permutation test, Δ = 3.70, p = .066

Mean difference (OJ − VC)
3.700
p
.066
Permutations
1,999

Effect size

  • Cohen's d 0.4945

Plots

len by suppHow do groups compare in shape, summary and individual observations at once?
View data
supplen
VC4.200
VC11.500
VC7.300
VC5.800
VC6.400
VC10
VC11.200
VC11.200
VC5.200
VC7
VC16.500
VC16.500
VC15.200
VC17.300
VC22.500
VC17.300
VC13.600
VC14.500
VC18.800
VC15.500
VC23.600
VC18.500
VC33.900
VC25.500
VC26.400
VC32.500
VC26.700
VC21.500
VC23.300
VC29.500
OJ15.200
OJ21.500
OJ17.600
OJ9.700
OJ14.500
OJ10
OJ8.200
OJ9.400
OJ16.500
OJ9.700
OJ19.700
OJ23.300
OJ23.600
OJ26.400
OJ20
OJ25.200
OJ25.800
OJ21.200
OJ14.500
OJ27.300
OJ25.500
OJ26.400
OJ22.400
OJ24.500
OJ24.800
OJ30.900
OJ26.400
OJ27.300
OJ29.400
OJ23

Assumptions

  • Exchangeability — Variance ratio 1.57.
  • Difference = OJ − VC; 1999 Monte Carlo permutations, seed 42; alternative: two-sided. p = (count + 1) / (permutations + 1).
The exact R script · R R version 4.5.1 (2025-06-13)
# Permutation test (two independent groups)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method permutation.two_sample 1.0.2 · spec 6a63b6b68eef47d9
# 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
alternative <- "two-sided"
seed <- 42  # shared Wichmann-Hill stream: Python draws the same permutations
r <- cs_perm_two_sample(x1, x2, alternative = alternative, max_exact = 200000, b = 1999, seed = seed)
n1 <- length(x1)
n2 <- length(x2)
sp <- sqrt(((n1 - 1) * var(x1) + (n2 - 1) * var(x2)) / (n1 + n2 - 2))
# Cohen's d is undefined when neither sample varies (pooled SD 0): published as null.
no_spread <- length(unique(x1)) < 2 && length(unique(x2)) < 2
d <- if (no_spread) NA_real_ else r$diff / sp

# %% Assumptions
v1 <- var(x1)
v2 <- var(x2)
ratio <- if (min(v1, v2) > 0) max(v1, v2) / min(v1, v2) else Inf
assumptions <- list(list(key = "exchangeability", label = "Exchangeability", status = if (ratio > 4) "warn" else "pass",
                         detail = paste0(sprintf("Variance ratio %.2f", ratio),
                                         if (ratio > 4) "; very different spreads make the labels non-exchangeable (consider Welch's test)." else ".")))

# %% Result
values <- list(diff = r$diff, p = r$p, n_perm = r$n_perm, exact = r$exact, count = r$count, mean_1 = mean(x1), mean_2 = mean(x2),
               n_1 = n1, n_2 = n2, cohens_d = d, level_1 = label_1, level_2 = label_2)
chart_rows <- unique(round(seq(1, nrow(df), length.out = min(nrow(df), 5000))))
values$missing_share <- if (n_input > 0) n_dropped / n_input else 0  # consult-a-statistician input
how <- if (r$exact) "exact (all splits)" else sprintf("%d Monte Carlo permutations, seed %d", as.integer(r$n_perm), as.integer(seed))
cs_publish(list(
  method = "permutation.two_sample",
  methodVersion = "1.0.2",
  title = "Permutation test",
  engine = cs_engine_info("stats", "nanoparquet"),
  n = n1 + n2,
  summary = sprintf("Difference in means %.3f; permutation %s (%s).", r$diff, cs_fmt_p(r$p), how),
  apa = sprintf("permutation test, Δ = %s, %s", cs_fmt_num(r$diff), cs_fmt_p(r$p)),
  statistics = list(list(key = "diff", label = sprintf("Mean difference (%s − %s)", label_1, label_2), value = r$diff),
                    list(key = "p", label = "p", value = r$p, format = "p"),
                    list(key = "n_perm", label = "Permutations", value = r$n_perm, format = "integer")),
  effectSizes = list(list(key = "cohens_d", label = "Cohen's d", value = d, method = "pooled SD")),
  assumptions = assumptions,
  warnings = warnings,
  notes = list(paste0(sprintf("Difference = %s − %s; %s; alternative: %s. ", label_1, label_2, how, alternative),
                      if (r$exact) "p = count / total." else "p = (count + 1) / (permutations + 1).")),
  values = values,
  charts = list(cs_chart("distribution", "raincloud", sprintf("%s by %s", y, g),
                         list(y = cs_col(y, df[[y]][chart_rows]), group = cs_col(g, as.character(df[[g]][chart_rows]), levels = levels_g))))
))
Python

permutation test, Δ = 3.70, p = .066

Mean difference (OJ − VC)
3.700
p
.066
Permutations
1,999

Effect size

  • Cohen's d 0.4945

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

Assumptions

  • Exchangeability — Variance ratio 1.57.
  • Difference = OJ − VC; 1999 Monte Carlo permutations, seed 42; alternative: two-sided. p = (count + 1) / (permutations + 1).
The exact Python script · Python Python 3.13.5 · scipy 1.18.1 · pandas 3.1.0
# Permutation test (two independent groups)
# Generated by CodeSplash Analytics 1.0.0 on 2026-11-09 · method permutation.two_sample 1.0.2 · spec 6a63b6b68eef47d9
# 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 permutation

# %% 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
alternative = "two-sided"
seed = 42  # shared Wichmann–Hill stream: R draws the same permutations
r = permutation.two_sample(x1, x2, alternative=alternative, max_exact=200000, b=int(1999), seed=seed)
n1, n2 = len(x1), len(x2)
sp = np.sqrt(((n1 - 1) * np.var(x1, ddof=1) + (n2 - 1) * np.var(x2, ddof=1)) / (n1 + n2 - 2))
# Cohen's d is undefined when neither sample varies (pooled SD 0): published as null, as in R.
no_spread = len(np.unique(x1)) < 2 and len(np.unique(x2)) < 2
d = None if no_spread else float(r["diff"] / sp)

# %% Assumptions
# A sample with no spread has exactly zero variance (np.var can leave rounding noise), as in R.
v1 = 0.0 if len(np.unique(x1)) < 2 else np.var(x1, ddof=1)
v2 = 0.0 if len(np.unique(x2)) < 2 else np.var(x2, ddof=1)
ratio = max(v1, v2) / min(v1, v2) if min(v1, v2) > 0 else float("inf")
assumptions = [{"key": "exchangeability", "label": "Exchangeability", "status": "warn" if ratio > 4 else "pass",
                "detail": f"Variance ratio {ratio:.2f}" + ("; very different spreads make the labels non-exchangeable (consider Welch's test)." if ratio > 4 else ".")}]

# %% Result
values = {"diff": r["diff"], "p": r["p"], "n_perm": r["n_perm"], "exact": r["exact"], "count": r["count"], "mean_1": float(x1.mean()),
          "mean_2": float(x2.mean()), "n_1": n1, "n_2": n2, "cohens_d": d, "level_1": label_1, "level_2": label_2}
chart_rows = np.unique(np.round(np.linspace(0, len(df) - 1, min(len(df), 5000))).astype(int))
how = "exact (all splits)" if r["exact"] else f"{r['n_perm']} Monte Carlo permutations, seed {seed}"
values["missing_share"] = n_dropped / n_input if n_input else 0.0  # consult-a-statistician input
cs.publish({
    "method": "permutation.two_sample",
    "methodVersion": "1.0.2",
    "title": "Permutation test",
    "engine": cs.engine_info("pandas", "numpy"),
    "n": n1 + n2,
    "summary": f"Difference in means {r['diff']:.3f}; permutation {cs.fmt_p(r['p'])} ({how}).",
    "apa": f"permutation test, Δ = {cs.fmt_num(r['diff'])}, {cs.fmt_p(r['p'])}",
    "statistics": [{"key": "diff", "label": f"Mean difference ({label_1} − {label_2})", "value": r["diff"]},
                   {"key": "p", "label": "p", "value": r["p"], "format": "p"},
                   {"key": "n_perm", "label": "Permutations", "value": r["n_perm"], "format": "integer"}],
    "effectSizes": [{"key": "cohens_d", "label": "Cohen's d", "value": d, "method": "pooled SD"}],
    "assumptions": assumptions,
    "warnings": warnings,
    "notes": [f"Difference = {label_1} − {label_2}; {how}; alternative: {alternative}. "
              + ("p = count / total." if r["exact"] else "p = (count + 1) / (permutations + 1).")],
    "values": values,
    "charts": [cs.chart("distribution", "raincloud", f"{y} by {g}", {
        "y": cs.col(y, df[y].to_numpy(dtype=float)[chart_rows]),
        "group": cs.col(g, df[g].astype(str).to_numpy()[chart_rows], levels=levels)})],
})

The strip on a result card tells you how closely Python and R agree for that method. That guards against a bug in one engine, and is a stronger check than rerunning one engine twice. It can't protect you from choosing the wrong test: two engines can agree on an analysis of the wrong question.

05

Your part

Reflect

Software can record what you did. Only you can record why. For a recent analysis, write three sentences:

  • What question was this answering, and who decided that?
  • Which rows or columns did you leave out, and why?
  • What did you try that you aren't showing?

The third is the hardest, and the one a reader most needs. If you can't answer it, you can't tell them how much to trust the result.

06

Check your understanding

Checkpoint

Check yourself · choose all that apply

Which of these are needed to reproduce a Monte Carlo result exactly? Choose all that apply.

Show the answer

Answer: a, b, c

Data, options, seed and versions pin down the numbers. A screenshot shows what happened but doesn't let anyone rerun it.

Check yourself

A colleague reruns a bootstrap with several seeds and reports the one with the narrowest interval. What is wrong with that?

Show the answer

Answer: c

Seeds are arbitrary only until you pick the one you like. If results depend on the seed, the number of resamples is too small.

Check yourself

Python and R agree to ten decimals on your result. What has that established?

Show the answer

Answer: a

Agreement between engines checks the arithmetic. It says nothing about the design, the assumptions or the question.

07

Export a package

In the app

Run an analysis, then choose Export package from the result card's actions. The package has the data snapshot, code in every target, the rendered report, environment locks and saved results. It also carries the files the app builds before a run, such as network tables, spatial weights or a learner's split plan. When the analysis reads image or audio files, you choose whether to include their decoded arrays. An explanation of a saved model carries that model's files, and the export dialog shows how much they add. Verify reruns every script in clean processes, and compares the numbers at each method's parity tier.

08

Recap

Recap
  • Reproducing a result takes the data version, the preparation, the method and options, the versions, and the seed.
  • CodeSplash records those for you, and a package bundles them so anyone can verify the numbers.
  • Only you can record why you made your choices and what you tried along the way.

Concepts in this lesson