Skip to main content

The capacity to be upset

Building and checking models
Principle or heuristic
Intermediate
An important characteristic of a good scientist, to recognize anomalies for what they are, and to track them down and figure out what in our understanding is lacking.
Published

November 9, 2026

Modified

November 13, 2026

Entry #146 in Andrew Gelman’s Handy Statistical Lexicon. Original discussion: The role of doubt in conceiving research.

Filed under Building and checking models · Principle or heuristic · Intermediate.

Source check: ✓ The explanation was checked against the source.

What it is

Good scientists get upset by anomalies: a data point that shouldn’t be there, a result that contradicts the model, a number that doesn’t add up. They don’t explain it away as noise or move on. They take the discomfort as a signal that their understanding is incomplete, and they track down the cause. That capacity to be bothered is what turns surprises into discoveries.

Why it matters

Most anomalies are noise, so there’s a temptation to ignore all of them. But some aren’t, and those are where new understanding comes from: a data error, a broken model, a new phenomenon. A researcher who is never upset never finds them. One who is upset by everything never finishes. The skill is calibrated upset-ness: noticing deviations bigger than the noise can explain, and following them up.

How it works

Think of it as anomaly detection with a threshold. Flag a residual when it exceeds \(k\) standard deviations of what the model expects. A high \(k\) (hard to upset) misses real anomalies. A low \(k\) (easily upset) chases noise. The researcher with a well-calibrated \(k\), who also investigates what they flag, catches the real problems at a manageable cost in false alarms.

Simulated example

A stream of 300 measurements fits a model well, except that a real anomaly, a shift caused by an undetected problem, starts partway through. Set how easily the researcher gets upset.

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} from "../js/stats.js"

viewof k = Inputs.range([1, 5], {value: 2, step: 0.1, label: "How hard to upset (flag residuals beyond k sd)"})
viewof shift = Inputs.range([0, 3], {value: 1.2, step: 0.1, label: "Size of the real anomaly (sd units)"})
viewof seed = Inputs.range([1, 500], {value: 146, step: 1, label: "Random seed"})

upset = {
  const r = rng(seed);
  return range(300).map(t => {
    const real = t >= 200 && t < 240;
    const resid = r.normal(real ? shift : 0, 1);
    return {t, resid, real, flagged: Math.abs(resid) > k};
  });
}

Plot.plot({
  ariaLabel: "The capacity to be upset: simulation chart",
  ariaDescription: "Horizontal axis: Measurement. Vertical axis: Residual from the model (sd units). The chart updates with the controls above it, and the summary below the charts states the result in words.",
  height: 280,
  x: {label: "Measurement"},
  y: {label: "Residual from the model (sd units)", grid: true},
  marks: [
    Plot.rect([0], {x1: 200, x2: 240, y1: -5, y2: 6, fill: "#b8860b", fillOpacity: 0.12}),
    Plot.dot(upset, {x: "t", y: "resid", r: d => d.flagged ? 4 : 2, fill: d => d.flagged ? "#d6604d" : "#8a8a8a"}),
    Plot.ruleY([k, -k], {stroke: "#d6604d", strokeDasharray: "4 3"})
  ]
})
# The capacity to be upset: flagging residuals that don't fit.
1k <- 2 # how hard to upset: flag residuals beyond k sd
shift <- 1.2 # size of the real anomaly (sd units)
2set.seed(146)

t <- 0:299
3real <- t >= 200 & t < 240 # the real anomaly
4resid <- rnorm(300, ifelse(real, shift, 0), 1)
5flagged <- abs(resid) > k

cat(
  "Flagged", sum(real & flagged), "of the anomaly's 40 points, with",
  sum(!real & flagged), "false alarms elsewhere\n"
)

6plot(t, resid,
  pch = 19, cex = 0.6,
  col = ifelse(flagged, "#d6604d", "grey50"),
  xlab = "Measurement", ylab = "Residual (sd units)"
)
rect(200, -10, 240, 10, col = adjustcolor("#2166ac", 0.1), border = NA)
abline(h = c(-k, k), lty = 2)
1
The page’s controls: how far a residual must stray before it upsets you, and how large the real anomaly is.
2
Fixes the random numbers so the run is reproducible.
3
Forty consecutive measurements where the model is genuinely wrong.
4
Residuals: pure noise everywhere except inside the anomaly, where they are shifted.
5
The rule for being upset: flag any residual beyond k standard deviations.
6
Residuals over time, flagged ones in red, with the true anomaly shaded. Too high a k and the anomaly slips through; too low and false alarms pile up.
# The capacity to be upset: flagging residuals that don't fit.
import numpy as np
import matplotlib.pyplot as plt

k = 2        # how hard to upset: flag residuals beyond k sd
shift = 1.2  # size of the real anomaly (sd units)
rng = np.random.default_rng(146)

t = np.arange(300)
real = (t >= 200) & (t < 240)  # the real anomaly
resid = rng.normal(np.where(real, shift, 0), 1)
flagged = np.abs(resid) > k

print(f"Flagged {(real & flagged).sum()} of the anomaly's 40 points, with "
      f"{(~real & flagged).sum()} false alarms elsewhere")

plt.axvspan(200, 240, color="#2166ac", alpha=0.1)
plt.scatter(t, resid, s=8, c=np.where(flagged, "#d6604d", "0.5"))
plt.axhline(k, color="black", linestyle="--")
plt.axhline(-k, color="black", linestyle="--")
plt.xlabel("Measurement")
plt.ylabel("Residual (sd units)")
plt.show()

Key takeaways

  • Treat anomalies as information about what you don’t understand.
  • Calibrate how easily you get upset: not by every wiggle, and not by nothing.
  • Follow up. Being upset is only useful if it leads to an investigation.

Source

Back to top