A relationship seen inside each subgroup reverses when the groups are pooled. The coloured lines slope upward within each group, but the red pooled line slopes downward.
Seeded synthetic groups have adjustable means, spread, noise and a common within-group slope. Ordinary least-squares lines are fitted within groups, to the pooled sample and to the group means.
Pooled and within-group associations answer different questions. A reversal alone does not identify the causal effect or determine which variables should be adjusted for. The indicator here specifically detects a positive average within-group slope with a negative pooled slope; other reversals can be explored in the plot.
E. H. Simpson (1951), The Interpretation of Interaction in Contingency Tables. This is a continuous regression illustration of the aggregation effect. Implementation.