What were you doing before you had any data?
Building and checking models
Principle or heuristic
Advanced
Rubin’s second question.
What it is
The lexicon calls this “Rubin’s second question”, the companion to Donald Rubin’s first, “What would you do if you had all the data?” The linked post quotes only the first question, so the reading of the second below is ours. It asks what you knew and did before the data arrived. How were units selected and assigned to treatments? What did you already believe about plausible effect sizes? The answers make up the design and the prior, the parts of the analysis that don’t come from the data at hand but strongly shape what the data can tell you.
Why it matters
Analysts often act as if knowledge starts when the data file opens. But the assignment mechanism determines which comparisons are valid, and prior knowledge determines which estimates are plausible. A useful practical version of the question is the prior predictive check: before fitting, simulate data from your model and priors and ask whether they look like anything you would believe. “Uninformative” priors often turn out, on inspection, to imply absurd data.
How it works
For a logistic regression with \(K\) standardized predictors and independent \(\mathrm{N}(0, s^2)\) priors on the coefficients, the linear predictor \(\eta = \sum_k \beta_k x_k\) has prior sd of about \(s\sqrt{K}\). With \(s = 10\) and \(K = 5\), that is roughly 22 on the log-odds scale, so the prior says nearly every predicted probability is essentially 0 or 1. Most people before seeing any data would find that ridiculous. The prior predictive check makes the absurdity visible, and a scale like \(s = 1\) fixes it.
Simulated example
Simulate from the prior of a logistic regression with standardized predictors. Look at the implied predicted probabilities and ask: is this what you believed before the data?
Show simulation code
The R version uses base R, and the Python version uses NumPy and Matplotlib. Where the simulation draws random numbers, each language draws its own, so exact numbers differ slightly but show the same pattern. The numbered markers in the R code are explained under it.
import {rng, range, invLogit, pct} from "../js/stats.js"
viewof s = Inputs.range([0.1, 20], {value: 10, step: 0.1, label: "Prior sd on each coefficient"})
viewof K = Inputs.range([1, 20], {value: 5, step: 1, label: "Number of predictors"})
viewof seed = Inputs.range([1, 500], {value: 56, step: 1, label: "Random seed"})
priorPred = {
const r = rng(seed);
return range(4000).map(() => {
let eta = r.normal(0, 1);
for (let k = 0; k < K; k++) eta += r.normal(0, s) * r.normal(0, 1);
return {p: invLogit(eta)};
});
}
Plot.plot({
ariaLabel: "What were you doing before you had any data?: simulation chart",
ariaDescription: "Horizontal axis: Prior predicted probability. Vertical axis: Draws. The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 280,
x: {label: "Prior predicted probability", domain: [0, 1]},
y: {label: "Draws", grid: true},
marks: [Plot.rectY(priorPred, Plot.binX({y: "count"}, {x: "p", fill: "#2166ac", thresholds: 40, domain: [0, 1]})), Plot.ruleY([0])]
})# What were you doing before you had any data? A prior predictive check.
1s <- 10 # prior sd on each logistic regression coefficient
K <- 5 # number of standardized predictors
2set.seed(56)
# Linear predictor under the prior: intercept + sum of beta_k * x_k
3eta <- rnorm(4000) + rowSums(matrix(rnorm(4000 * K, 0, s) * rnorm(4000 * K),
ncol = K
))
4p <- plogis(eta) # implied predicted probabilities
5extreme <- mean(p < 0.01 | p > 0.99)
cat("Predicted probabilities below 1% or above 99%: ",
round(100 * extreme), "%\n",
sep = ""
)
cat("Try s <- 1 for a prior that implies a reasonable spread.\n")
6hist(p,
breaks = seq(0, 1, 0.025), col = "#2166ac", border = "white",
main = "", xlab = "Predicted probability implied by the prior",
ylab = "Draws"
)- 1
- The page’s controls: the prior standard deviation of each coefficient, and the number of standardized predictors.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- Draw coefficients from the prior and predictors from their distribution, and form the linear predictor. Its spread is about s times the square root of K.
- 4
- The predicted probabilities the prior implies, before any data.
- 5
- The share of predictions that are essentially 0 or 1. A wide prior says almost every case is a certainty.
- 6
- The prior predictive histogram. Set s to 1 and the pile-up at the edges disappears.
# What were you doing before you had any data? A prior predictive check.
import numpy as np
import matplotlib.pyplot as plt
s = 10 # prior sd on each logistic regression coefficient
K = 5 # number of standardized predictors
rng = np.random.default_rng(56)
# Linear predictor under the prior: intercept + sum of beta_k * x_k
beta = rng.normal(0, s, (4000, K))
x = rng.normal(size=(4000, K))
eta = rng.normal(size=4000) + (beta * x).sum(axis=1)
p = 1 / (1 + np.exp(-eta)) # implied predicted probabilities
extreme = np.mean((p < 0.01) | (p > 0.99))
print(f"Predicted probabilities below 1% or above 99%: {100 * extreme:.0f}%")
print("Try s = 1 for a prior that implies a reasonable spread.")
plt.hist(p, bins=np.arange(0, 1.001, 0.025), color="#2166ac")
plt.xlabel("Predicted probability implied by the prior")
plt.ylabel("Draws")
plt.show()Key takeaways
- Ask what you knew before the data: the design, the assignment mechanism, plausible effect sizes.
- Prior predictive checks show what your priors actually imply.
- “Vague” priors on coefficients can imply extreme, unbelievable predictions.
Source
- Andrew Gelman, Philosophy of Bayesian statistics: my reactions to Cox and Mayo (2012).
- Gabry, Simpson, Vehtari, Betancourt and Gelman, “Visualization in Bayesian workflow”, JRSS A (2019).