Each of the 260 points is a simulated individual with an unobserved confounder U, a binary instrument Z, a treatment X and an outcome Y:
U ~ N(0, 1) (hidden — affects both X and Y)
Z ~ Bernoulli(0.5) (instrument — independent of U)
X = a·Z + c·U + noise·ε₁ (treatment)
Y = β·X + c·U + noise·ε₂ (outcome, true effect β)
Because U pushes X and Y in the same direction, a naive regression of Y on X picks up both the real effect β and a spurious share of U — the red "Naive OLS" line is biased even though every point obeys the same true β. Toggle "Reveal hidden confounder" to tilt the view onto the U axis and see the points fan out along exactly the dimension the naive fit cannot see.
A valid instrument Z moves X (it has "relevance", shown as r(Z,X)) but has no direct arrow into Y — it can only affect Y through X. Two-stage least squares exploits that:
- Stage 1 — regress X on Z, keep the predicted values X̂ = â₀ + â₁Z (the part of X driven only by the instrument, with U's influence averaged out by Z's independence from U).
- Stage 2 — regress Y on X̂ instead of X. Because X̂ carries none of U's variation, its slope is a consistent estimate of the true β — the teal "2SLS" line tracks the true-β line even as you crank up confounding.
Sliding confounding strength to 0 makes the naive and 2SLS lines coincide (no bias to correct). Sliding instrument strength toward 0 makes Z barely move X — r(Z,X) collapses toward 0 and the 2SLS estimate gets noisy and unreliable, illustrating the "weak instrument" problem economists and epidemiologists worry about in real IV studies (e.g. using distance-to-clinic as an instrument for treatment uptake).