Field note · September 2, 2023

The overall average hides 5 different numbers

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

1 min read ·Analytics practice ·statistics practice

seniority splits data-job-postings into 5 groups. Here is what salary_max_usd looks like inside each.

  • lead — mean 171,459, median 190,000 (243 rows)
  • staff — mean 152,058, median 170,500 (339 rows)
  • senior — mean 127,309, median 144,000 (984 rows)
  • mid — mean 95,427, median 107,250 (1,170 rows)
  • junior — mean 65,340, median 74,000 (764 rows)

Top to bottom that is 171,459 against 65,340, a spread of 162.4%. The pooled average is 138,807.

sql
select seniority,
  count(*)                                                    as rows,
  round(avg(salary_max_usd)::numeric, 2)                      as mean,
  percentile_cont(0.5) within group (order by salary_max_usd) as median
from data_job_postings
group by 1
order by mean desc;

A spread that wide means the pooled number is not a summary, it is an artefact of the mix. Change the proportion of lead rows and the overall average moves without any individual group changing at all — which is how a metric goes up while every segment goes down.

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.