Field note · December 15, 2023

The overall average hides 6 different numbers

Real group means for one column across 6 segments, and what the pooled average conceals.

1 min read ·Analytics practice ·statistics practice

carrier splits flight-delays into 6 groups. Here is what sched_dep_hour looks like inside each.

  • AS — mean 13, median 13 (725 rows)
  • WN — mean 13, median 13 (1,652 rows)
  • UA — mean 13, median 13 (1,422 rows)
  • AA — mean 13, median 13 (1,751 rows)
  • B6 — mean 13, median 13 (766 rows)
  • DL — mean 12, median 13 (1,684 rows)

Top to bottom that is 13 against 12, a spread of 2.8%. The pooled average is 13.

sql
select carrier,
  count(*)                                                    as rows,
  round(avg(sched_dep_hour)::numeric, 2)                      as mean,
  percentile_cont(0.5) within group (order by sched_dep_hour) 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.