Cantor’s Corner
Building and checking models
Principle or heuristic
Advanced
Where you want to be.
What it is
The name alludes to Georg Cantor’s diagonal argument, which builds exactly the item that isn’t on your list. Gelman writes that “scientific research is all about discovery of the unexpected: to do research, you need to be open to new possibilities, to design experiments to force anomalies, and to learn from them. The sweet spot for any researcher is at Cantor’s corner.” (He points to section 7 of one of his articles for more on the Cantor connection.)
The post’s puzzle is that researchers are trained to be open to the unexpected, yet they respond to legitimate criticism of their own work “in an angry, defensive, closed, non-scientific way.” Gelman’s explanation is peer review. From their first submission, scientists receive sharp criticism and learn to respond “in the shallowest way possible”, treating each reviewer comment as a hoop to jump through rather than a possible sign the paper is wrong. That habit carries over to post-publication criticism.
Why it matters
Each critical comment is “potentially a sign that our paper is completely wrong.” A researcher who treats criticism as obstacles never ends up in Cantor’s corner, because they never let an anomaly change their claims. The researcher who does get there treats flaws as the most informative part of the analysis. In modeling terms, that means running checks designed to force anomalies, which is what the simulation below shows.
How it works
Fit a model, then go down a list of features of the data, such as the mean, the variance, the share of zeros and the maximum. For each one, ask whether the model reproduces it. The diagonal move is to look specifically for the feature the model was not built to capture. When you find it, you are in Cantor’s corner: you know something about your model’s limits that the defensive researcher will never learn.
Simulated example
Count data come from an overdispersed process with many zeros, and a Poisson model is fit. For each test statistic, compare the observed value with its distribution under the fitted model. The statistic the model fails on is your corner.
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, mean, variance, fmt} from "../js/stats.js"
viewof zeroInfl = Inputs.range([0, 0.5], {value: 0.25, step: 0.05, label: "Share of structural zeros in the truth"})
viewof seed = Inputs.range([1, 500], {value: 69, step: 1, label: "Random seed"})
corner = {
const r = rng(seed);
const y = range(300).map(() => r() < zeroInfl ? 0 : r.poisson(r.gamma(4, 1)));
const lam = mean(y); // Poisson fit
const stats = {
"Mean": v => mean(v), "Variance": v => variance(v),
"Share of zeros": v => v.filter(x => x === 0).length / v.length, "Maximum": v => Math.max(...v)
};
return Object.entries(stats).map(([name, T]) => {
const obs = T(y);
const reps = range(400).map(() => T(range(300).map(() => r.poisson(lam))));
const p = reps.filter(t => t >= obs).length / reps.length;
return {name, obs, reps, p};
});
}
Plot.plot({
ariaLabel: "Cantor's Corner: simulation chart",
ariaDescription: "Horizontal axis: Replicated statistic under the Poisson model (normalized). The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 360,
facet: {data: corner.flatMap(d => d.reps.map(v => ({name: d.name, v}))), y: "name", marginRight: 110},
x: {label: "Replicated statistic under the Poisson model (normalized)", grid: true},
y: {label: null, axis: null},
marks: [
Plot.rectY(corner.flatMap(d => { const m = mean(d.reps), s = Math.sqrt(variance(d.reps)) || 1; return d.reps.map(v => ({name: d.name, z: (v - m) / s})); }), Plot.binX({y: "count"}, {x: "z", fy: "name", fill: "#8a8a8a", thresholds: 30})),
Plot.ruleX(corner.map(d => { const m = mean(d.reps), s = Math.sqrt(variance(d.reps)) || 1; return {name: d.name, z: (d.obs - m) / s}; }), {x: "z", fy: "name", stroke: "#d6604d", strokeWidth: 3})
]
})# Cantor's Corner: find the statistic your model can't reproduce.
1zero_infl <- 0.25 # share of structural zeros in the truth
2set.seed(69)
3y <- ifelse(runif(300) < zero_infl, 0, rpois(300, rgamma(300, 4, 1)))
4lambda <- mean(y) # fit a Poisson model
stats <- list(
Mean = mean, Variance = var,
"Share of zeros" = function(v) mean(v == 0), Maximum = max
)
5reps <- replicate(400, rpois(300, lambda)) # 400 datasets from the fit
6res <- t(sapply(stats, function(f) {
sim <- apply(reps, 2, f)
c(observed = f(y), simulated_mean = mean(sim), p = mean(sim >= f(y)))
}))
print(round(res, 3)) # p near 0 or 1: the model misses this feature
7par(mfrow = c(2, 2))
for (name in names(stats)) {
sim <- apply(reps, 2, stats[[name]])
hist(sim,
col = "grey80", border = "white", main = name,
xlim = range(sim, stats[[name]](y)), xlab = "Simulated from the model"
)
abline(v = stats[[name]](y), col = "#d6604d", lwd = 3)
}- 1
- The page’s control: the share of structural zeros in the real data.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- The truth is overdispersed and zero-inflated. The model will be a plain Poisson.
- 4
- The Poisson fit: one parameter, the mean.
- 5
- Four hundred datasets simulated from the fitted model.
- 6
- For each test statistic, where the observed value falls among the simulated ones. A p-value near 0 or 1 marks a feature the model can’t reproduce: Cantor’s corner.
- 7
- One histogram per statistic, with the observed value in red. The mean is always matched; the variance and the zeros are not.
# Cantor's Corner: find the statistic your model can't reproduce.
import numpy as np
import matplotlib.pyplot as plt
zero_infl = 0.25 # share of structural zeros in the truth
rng = np.random.default_rng(69)
y = np.where(rng.uniform(size=300) < zero_infl, 0,
rng.poisson(rng.gamma(4, 1, 300)))
lam = y.mean() # fit a Poisson model
stats = {"Mean": np.mean, "Variance": lambda v: v.var(ddof=1),
"Share of zeros": lambda v: np.mean(v == 0), "Maximum": np.max}
reps = rng.poisson(lam, (400, 300)) # 400 datasets from the fit
fig, axes = plt.subplots(2, 2, figsize=(8, 6))
for ax, (name, f) in zip(axes.flat, stats.items()):
sim = np.array([f(r) for r in reps])
obs = f(y)
print(f"{name}: observed {obs:.3f}, simulated mean {sim.mean():.3f}, "
f"p = {np.mean(sim >= obs):.3f}")
ax.hist(sim, bins=20, color="0.8")
ax.axvline(obs, color="#d6604d", linewidth=3)
ax.set_title(name)
plt.tight_layout()
plt.show()Key takeaways
- Look for the case your model gets wrong. Finding it is progress, not defeat.
- Design checks to break your model, not checks it is sure to pass.
- Researchers who look for their own counterexamples learn more than those who wait for critics to find them.