Show every road with a specification curve
Instead of choosing one analysis and defending it, run all the defensible ones and show how the estimate moves. Learn to read a specification curve, build a fair set, and report it.
What runs in CodeSplash
- Two-sample t-test (Welch / Student, or z test) Verified in Python and R
- Linear regression (OLS) Verified in Python and R
You will be able to
- Read a specification curve and find the choices that drive a result
- Decide which specifications are fair to include
- Report a curve without turning it into a vote
Read first
Forty percent
PredictPredict first
You rerun an analysis under 128 reasonable specifications. All the estimates have the same sign, and about 40% are significant. What do you conclude?
Reveal
The answer depends on the choices, so find out which. Share significant isn't a verdict in either direction. The curve's value is in showing which choice moves the result.
Read the picture
ExploreA specification curveSpecification curveEvery defensible version of an analysis, sorted by estimate, with a panel showing the choices behind each one. has two panels. On top, one estimate per specification, sorted by size, with significant ones colored. Below, a dot for each choice that specification used.
Look down a column of dots. Then look across a row: if the dots for one choice bunch at one end, that choice is driving the result.
View data
| specification | effect (SD) | ci_low | ci_high | significant | dimension | option |
|---|---|---|---|---|---|---|
| 1 | 0.0959 | −0.0158 | 0.2076 | false | covariates | full set |
| 1 | 0.0959 | −0.0158 | 0.2076 | false | outliers | winsorize 1% |
| 1 | 0.0959 | −0.0158 | 0.2076 | false | outcome | log |
| 1 | 0.0959 | −0.0158 | 0.2076 | false | sample | complete cases |
| 2 | 0.1000 | 0.0118 | 0.1882 | true | covariates | full set |
| 2 | 0.1000 | 0.0118 | 0.1882 | true | outliers | winsorize 1% |
| 2 | 0.1000 | 0.0118 | 0.1882 | true | outcome | log |
| 2 | 0.1000 | 0.0118 | 0.1882 | true | sample | all |
| 3 | 0.1030 | 0.0148 | 0.1912 | true | covariates | full set |
| 3 | 0.1030 | 0.0148 | 0.1912 | true | outliers | drop |z| > 3 |
| 3 | 0.1030 | 0.0148 | 0.1912 | true | outcome | log |
| 3 | 0.1030 | 0.0148 | 0.1912 | true | sample | all |
| 4 | 0.1115 | −0.0002 | 0.2232 | false | covariates | full set |
| 4 | 0.1115 | −0.0002 | 0.2232 | false | outliers | drop |z| > 3 |
| 4 | 0.1115 | −0.0002 | 0.2232 | false | outcome | log |
| 4 | 0.1115 | −0.0002 | 0.2232 | false | sample | complete cases |
| 5 | 0.1268 | 0.0386 | 0.2150 | true | covariates | full set |
| 5 | 0.1268 | 0.0386 | 0.2150 | true | outliers | keep |
| 5 | 0.1268 | 0.0386 | 0.2150 | true | outcome | log |
| 5 | 0.1268 | 0.0386 | 0.2150 | true | sample | all |
| 6 | 0.1298 | 0.0180 | 0.2415 | true | covariates | age + sex |
| 6 | 0.1298 | 0.0180 | 0.2415 | true | outliers | drop |z| > 3 |
| 6 | 0.1298 | 0.0180 | 0.2415 | true | outcome | log |
| 6 | 0.1298 | 0.0180 | 0.2415 | true | sample | complete cases |
| 7 | 0.1404 | 0.0286 | 0.2521 | true | covariates | full set |
| 7 | 0.1404 | 0.0286 | 0.2521 | true | outliers | keep |
| 7 | 0.1404 | 0.0286 | 0.2521 | true | outcome | log |
| 7 | 0.1404 | 0.0286 | 0.2521 | true | sample | complete cases |
| 8 | 0.1447 | 0.0330 | 0.2565 | true | covariates | full set |
| 8 | 0.1447 | 0.0330 | 0.2565 | true | outliers | winsorize 1% |
| 8 | 0.1447 | 0.0330 | 0.2565 | true | outcome | raw |
| 8 | 0.1447 | 0.0330 | 0.2565 | true | sample | complete cases |
| 9 | 0.1448 | 0.0566 | 0.2330 | true | covariates | full set |
| 9 | 0.1448 | 0.0566 | 0.2330 | true | outliers | winsorize 1% |
| 9 | 0.1448 | 0.0566 | 0.2330 | true | outcome | raw |
| 9 | 0.1448 | 0.0566 | 0.2330 | true | sample | all |
| 10 | 0.1516 | 0.0634 | 0.2398 | true | covariates | age + sex |
| 10 | 0.1516 | 0.0634 | 0.2398 | true | outliers | winsorize 1% |
| 10 | 0.1516 | 0.0634 | 0.2398 | true | outcome | log |
| 10 | 0.1516 | 0.0634 | 0.2398 | true | sample | all |
| 11 | 0.1530 | 0.0413 | 0.2648 | true | covariates | none |
| 11 | 0.1530 | 0.0413 | 0.2648 | true | outliers | winsorize 1% |
| 11 | 0.1530 | 0.0413 | 0.2648 | true | outcome | log |
| 11 | 0.1530 | 0.0413 | 0.2648 | true | sample | complete cases |
| 12 | 0.1578 | 0.0460 | 0.2695 | true | covariates | age + sex |
| 12 | 0.1578 | 0.0460 | 0.2695 | true | outliers | winsorize 1% |
| 12 | 0.1578 | 0.0460 | 0.2695 | true | outcome | log |
| 12 | 0.1578 | 0.0460 | 0.2695 | true | sample | complete cases |
| 13 | 0.1581 | 0.0699 | 0.2463 | true | covariates | age + sex |
| 13 | 0.1581 | 0.0699 | 0.2463 | true | outliers | drop |z| > 3 |
| 13 | 0.1581 | 0.0699 | 0.2463 | true | outcome | log |
| 13 | 0.1581 | 0.0699 | 0.2463 | true | sample | all |
| 14 | 0.1606 | 0.0489 | 0.2723 | true | covariates | full set |
| 14 | 0.1606 | 0.0489 | 0.2723 | true | outliers | drop |z| > 3 |
| 14 | 0.1606 | 0.0489 | 0.2723 | true | outcome | raw |
| 14 | 0.1606 | 0.0489 | 0.2723 | true | sample | complete cases |
| 15 | 0.1747 | 0.0865 | 0.2629 | true | covariates | full set |
| 15 | 0.1747 | 0.0865 | 0.2629 | true | outliers | drop |z| > 3 |
| 15 | 0.1747 | 0.0865 | 0.2629 | true | outcome | raw |
| 15 | 0.1747 | 0.0865 | 0.2629 | true | sample | all |
First 60 of 144 rows.
Open it in Charts for a guide to each panel.
What belongs on the curve
ReadInclude a specification only if you'd have been willing to report it as your main analysis. Three questions help:
- Does it estimate the same thing? A trimmed mean and a mean are different targets.
- Is it statistically valid for these data?
- Would a reasonable colleague have chosen it?
Leave out poor specifications and you hide a weakness in the result. Add them and you bury the good ones, so the set you list shapes the picture. Report how you chose it. Multiverse analysisMultiverse analysisRunning an analysis under every reasonable combination of data-processing and modeling choices. is the same idea, applied to data-processing choices as well.
Is it fair?
CheckpointCheck yourself · choose all that apply
You're estimating the effect of a price change on revenue per user. Which belong on the curve? Choose all that apply.
Show the answer
Answer: a, b, c
The first three are defensible choices about the same question. The fourth doesn't estimate the effect at all, and the fifth selects on the outcome.
Check yourself
In a curve, every significant specification removes outliers, and every specification that keeps them isn't significant. How do you report this?
Show the answer
Answer: c
That pattern is the most useful thing a curve can show. Now you know exactly which rows to go and look at.
Not a vote
PredictPredict first
Suppose 90% of 128 specifications are significant. Is that like 115 independent studies agreeing?
Reveal
No. They all reuse the same rows, so they share the same luck. Removing one outlier changes all of them together. A curve shows how stable the result is to your choices. It doesn't add evidence, and a share of specifications isn't a p-value.
A small one by hand
ReflectRun this on ToothGrowth: three transformations, three row subsets and two tests. Before you run it, write down which single choice you expect to matter most. Then check.
import itertools
import numpy as np
import pandas as pd
from scipy import stats
df = pd.read_csv("toothgrowth.csv")
rows = []
subsets = {"all doses": [0.5, 1, 2], "without 2": [0.5, 1], "without 0.5": [1, 2]}
for tr, sub, welch in itertools.product(["raw", "log", "rank"], subsets, [True, False]):
d = df[df["dose"].isin(subsets[sub])]
y = {"raw": d["len"], "log": np.log(d["len"]), "rank": d["len"].rank()}[tr]
r = stats.ttest_ind(y[d["supp"] == "OJ"], y[d["supp"] == "VC"], equal_var=not welch)
rows.append((tr, sub, "Welch" if welch else "Student", r.statistic, r.pvalue))
print(pd.DataFrame(rows, columns=["outcome", "subset", "test", "t", "p"]).sort_values("t"))df <- read.csv("toothgrowth.csv")
subsets <- list("all doses" = c(0.5, 1, 2), "without 2" = c(0.5, 1), "without 0.5" = c(1, 2))
grid <- expand.grid(outcome = c("raw", "log", "rank"), subset = names(subsets),
welch = c(TRUE, FALSE), stringsAsFactors = FALSE)
res <- t(apply(grid, 1, function(g) {
d <- df[df$dose %in% subsets[[g[["subset"]]]], ]
y <- switch(g[["outcome"]], raw = d$len, log = log(d$len), rank = rank(d$len))
r <- t.test(y[d$supp == "OJ"], y[d$supp == "VC"], var.equal = g[["welch"]] == "FALSE")
c(t = unname(r$statistic), p = r$p.value)
}))
cbind(grid, res)[order(res[, "t"]), ]On your own result
In the appSave and run an analysis, then press Specification curve in the header of its result card. Tick what may vary: Covariates, Outcome rules and transformations, Row subsets and Alternative methods. Then press Run.
The dialog reports specifications run, the share significant, the share with the same sign as your analysis, and the median estimate. Every specification lists them all. Nothing is saved as a new analysis or counted as a new test. In the Meta-analysis studio, Multiverse does this for pooled estimates.
How to write it up
CheckpointCheck yourself
Which sentence reports a curve best?
Show the answer
Answer: c
Give the set, the range, the sign and what moved the result. "Robust" on its own tells the reader nothing about what you tried.
Recap
Recap- A specification curve replaces one chosen analysis with all the defensible ones, and shows what drives the result.
- Include only specifications you'd have reported as your main analysis, and say how you chose them.
- The specifications share data, so a share of them isn't a vote or a p-value.
Concepts in this lesson