Field note · May 21, 2023
year by region: a wide spread
Real group means for one column across 5 segments, and what the pooled average conceals.
Breaking year down by region on world-indicators, because the headline average is 2,012 and no segment is actually there.
Europe— mean 2,012, median 2,012 (192 rows)Americas— mean 2,012, median 2,012 (144 rows)Africa— mean 2,012, median 2,012 (144 rows)Asia— mean 2,012, median 2,012 (168 rows)Oceania— mean 2,012, median 2,012 (72 rows)
Top to bottom that is 2,012 against 2,012. The pooled average is 2,012.
select region,
count(*) as rows,
round(avg(year)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by year) as median
from world_indicators
group by 1
order by mean desc;The groups are close enough that the pooled average is a fair summary. That is worth confirming rather than assuming: the check costs one query and the failure mode is invisible.
Notice the mean and median columns disagree only slightly here. Always compute both in the group-by. The comparison between them per segment is free and tells you whether you are looking at a level difference or a tail difference.
This is the setup for Simpson's paradox — the case where every segment moves one way and the total moves the other.