Causality Sandbox

Generate synthetic data from different causal structures and inspect how correlation and slope change.

Loading interactive simulation...

why causal graphs beat correlation tables 🖖

A correlation tells you two variables move together โ€” not why. The same number can arise from three fundamentally different structures:

Direct cause (X โ†’ Y): removing X changes Y.
Confounder (Z โ†’ X, Z โ†’ Y): Z causes both; X and Y are correlated but neither causes the other. Controlling for Z kills the correlation.
Collider (X โ†’ Z โ† Y): X and Y are independent, but if you select or condition on Z, you create a spurious link between them.

The Directed Acyclic Graph (DAG) in the chart encodes which variables are causes and which are effects. Without it, you cannot distinguish these cases from a single correlation coefficient โ€” which is why causal inference always starts with a structural model, not a correlation matrix.

correlation is seeing, causation is doing 🖖

Everything here turns on the gap between watching a variable and changing it. Confounders and colliders both fool you because you only ever observe data that some hidden process already shaped. A randomized experiment cuts through this: assigning X by a coin flip severs every arrow pointing into X, so any correlation with Y that survives must be causal. That is why a controlled trial can settle a question no amount of observational data ever can.

the Berkeley admissions paradox 🖖

The Simpson scenario is no toy. In 1973 UC Berkeley's graduate admissions showed about 44% of men admitted against 35% of women, hinting at bias. Yet department by department, women were admitted at slightly higher rates โ€” they had simply applied in far larger numbers to the most competitive departments. Aggregating across departments flipped the within-group trend, exactly the reversal the dashed line traces in this tool.

Problem solved in full

  1. Correlation of โˆ’0.887 across 400 points with Z held fixed 6 steps

    X and Y correlate at โˆ’0.887 across 400 points. Work out how much of that survives once Z is held fixed, and say how confident you are allowed to be in either number.

    1. Three correlations, all measured from the same 400 points. Everything below is arithmetic on these three numbers โ€” no further access to the data is needed, which is the useful part.

    2. The partial correlation asks what is left of Xโ€“Y once the part of each that Z explains is subtracted. The formula is the correlation of the two residuals, written out in terms of the raw correlations.

    3. The numerator is where the answer is decided. Z's effect on X times Z's effect on Y accounts for 0.8805 of the 0.8871 observed โ€” the correlation is a shadow, not a signal.

    4. The denominator only rescales. Note it is built from the variance not explained by Z, which is why a Z that explains almost everything makes the estimate unstable.

    5. Now put an error bar on both. Fisher's transformation turns a correlation into something roughly normal, and multiplying by โˆš(nโˆ’3) gives the distance from zero in standard errors.

    6. For a rough check the standard error of r near zero is 1/โˆš(nโˆ’3). At 0.050, a partial correlation of โˆ’0.055 is one standard error out.

    Answer

    Almost none of it survives: โˆ’0.0553. Convert both to Fisher's z and the raw correlation stands 28 standard errors from zero while the partial correlation stands 1.1 โ€” the difference between the most certain thing in the dataset and a result you would expect from noise a quarter of the time. Two warnings come free with that. The partial correlation is a difference of two nearly equal numbers, 0.8871 against 0.8805, so the four digits you feed in buy you barely two in the answer. And this arithmetic cannot tell you Z is a confounder rather than a mediator; that came from knowing what Z is. Conditioning on a mediator destroys a real effect just as thoroughly as conditioning on a confounder destroys a false one.

References (1)

Example problems

  • Causal - X causes Y and nothing else does: r = 0.9401, and holding Z fixed leaves it at 0.9400. Z has no arrow in this graph, so controlling for it changes nothing. This is the control.
  • Confounder - r = -0.8871 between X and Y, and neither causes the other. Hold Z fixed and it collapses to -0.0553: almost all of that correlation was Z.
  • Collider - X and Y are independent by construction. Selecting on Z keeps 143 of 400 points and already shows r = -0.4288; conditioning on Z as well takes it to -0.8127. The association is entirely manufactured.
  • Simpson - The pooled slope is +0.121 and both subgroups slope -0.619 and -0.624. Every individual trend points down while the aggregate points up.