Field note · April 12, 2024
flight_no by origin: a 8% spread
Real group means for one column across 14 segments, and what the pooled average conceals.
Breaking flight_no down by origin on flight-delays, because the headline average is 3,560 and no segment is actually there.
SFO— mean 3,712, median 3,729 (551 rows)DTW— mean 3,648, median 3,703 (564 rows)DFW— mean 3,648, median 3,651 (612 rows)MSP— mean 3,633, median 3,739 (567 rows)JFK— mean 3,617, median 3,800 (548 rows)PHX— mean 3,594, median 3,595 (571 rows)
Top to bottom that is 3,712 against 3,431, a spread of 8.2%. The pooled average is 3,560.
select origin,
count(*) as rows,
round(avg(flight_no)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by flight_no) as median
from flight_delays
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.