sqrt(12^2 + 5^2)
Building and checking models
Principle or heuristic
Introductory
13.
What it is
Independent sources of variation add in quadrature: their standard deviations combine as the square root of the sum of squares. With 12 and 5, the total is \(\sqrt{144 + 25} = 13\), barely more than the larger one alone. Gelman calls the formula “so, so important”: “when you have two sources of variation, only the larger one matters (unless the variances are very close to each other). It comes up all the time in multilevel modeling.” For example, when within-group variation is much larger than between-group variation, the group-level component barely changes the total, and the reverse is also true.
Why it matters
Effort often goes to whichever error source is easiest to measure or most familiar, such as more decimal places or a slightly better instrument, while the dominant source, such as sampling variation, non-response or model misspecification, is left alone. Because of quadrature, eliminating the small source entirely reduces the total from 13 to 12. Halving the big source reduces it to about 7.8.
How it works
For independent errors with standard deviations \(\sigma_1\) and \(\sigma_2\),
\[ \sigma_{\text{total}} = \sqrt{\sigma_1^2 + \sigma_2^2}. \]
The marginal benefit of reducing \(\sigma_k\) is \(\partial \sigma_{\text{total}} / \partial \sigma_k = \sigma_k / \sigma_{\text{total}}\), which is proportional to the source’s size. Small sources contribute almost nothing at the margin.
Simulated example
Two independent error sources. Compare the total error after halving each one, both from the formula and by Monte Carlo.
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, sd, fmt} from "../js/stats.js"
viewof s1 = Inputs.range([0, 20], {value: 12, step: 0.5, label: "Error source 1 (sd)"})
viewof s2 = Inputs.range([0, 20], {value: 5, step: 0.5, label: "Error source 2 (sd)"})
viewof seed = Inputs.range([1, 500], {value: 101, step: 1, label: "Random seed"})
quad = {
const r = rng(seed);
const mc = (a, b) => sd(range(20000).map(() => r.normal(0, a) + r.normal(0, b)));
return [
{scenario: "As is", formula: Math.hypot(s1, s2), sim: mc(s1, s2)},
{scenario: "Halve source 1", formula: Math.hypot(s1 / 2, s2), sim: mc(s1 / 2, s2)},
{scenario: "Halve source 2", formula: Math.hypot(s1, s2 / 2), sim: mc(s1, s2 / 2)},
{scenario: "Eliminate source 2", formula: Math.hypot(s1, 0), sim: mc(s1, 0)}
];
}
Plot.plot({
ariaLabel: "sqrt(12^2 + 5^2): simulation chart",
ariaDescription: "Horizontal axis: Total error (sd). The chart updates with the controls above it, and the summary below the charts states the result in words.",
height: 200,
marginLeft: 140,
x: {label: "Total error (sd)", grid: true},
y: {label: null, domain: quad.map(d => d.scenario)},
marks: [Plot.barX(quad, {y: "scenario", x: "formula", fill: "#2166ac"}), Plot.dot(quad, {y: "scenario", x: "sim", fill: "#d6604d", r: 5}), Plot.ruleX([0])]
})# sqrt(12^2 + 5^2) = 13: independent errors add in quadrature.
1s1 <- 12 # error source 1 (sd)
s2 <- 5 # error source 2 (sd)
2set.seed(101)
3mc <- function(a, b) sd(rnorm(20000, 0, a) + rnorm(20000, 0, b))
scen <- rbind(
"As is" = c(s1, s2), "Halve source 1" = c(s1 / 2, s2),
"Halve source 2" = c(s1, s2 / 2),
"Eliminate source 2" = c(s1, 0)
)
total <- cbind(
4 formula = sqrt(scen[, 1]^2 + scen[, 2]^2),
simulated = apply(scen, 1, function(s) mc(s[1], s[2]))
)
print(round(total, 2)) # total error (sd) in each scenario
par(mar = c(4, 9, 1, 1))
5barplot(rev(total[, "formula"]),
horiz = TRUE, las = 1,
col = "#2166ac", xlab = "Total error (sd)"
)- 1
- The page’s controls: the two error sources’ standard deviations.
- 2
- Fixes the random numbers so the run is reproducible.
- 3
- A Monte Carlo check: the standard deviation of the sum of two independent errors.
- 4
- The formula: independent errors add in quadrature, so the larger one dominates.
- 5
- Total error in each scenario. Halving the small source barely helps; work on the big one.
# sqrt(12^2 + 5^2) = 13: independent errors add in quadrature.
import numpy as np
import matplotlib.pyplot as plt
s1 = 12 # error source 1 (sd)
s2 = 5 # error source 2 (sd)
rng = np.random.default_rng(101)
def mc(a, b):
return np.std(rng.normal(0, a, 20000) + rng.normal(0, b, 20000))
scen = {"As is": (s1, s2), "Halve source 1": (s1 / 2, s2),
"Halve source 2": (s1, s2 / 2), "Eliminate source 2": (s1, 0)}
for k, (a, b) in scen.items():
print(f"{k}: formula {np.hypot(a, b):.2f}, simulated {mc(a, b):.2f}")
plt.barh(list(scen)[::-1], [np.hypot(a, b) for a, b in scen.values()][::-1],
color="#2166ac")
plt.xlabel("Total error (sd)")
plt.tight_layout()
plt.show()Key takeaways
- Independent errors add in quadrature, so the largest source dominates.
- Reducing a small source of error barely helps. Find and attack the big one.
- In surveys and experiments, that’s usually sampling error, non-response or model error, not instrument precision.
Source
- Andrew Gelman, The most important formula in statistics: sqrt(12^2+5^2)=13 (2008).