Field note · February 9, 2024
rating by genre: a 16% spread
Real group means for one column across 8 segments, and what the pooled average conceals.
Breaking rating down by genre on movie-ratings, because the headline average is 3.62 and no segment is actually there.
romance— mean 3.96, median 4.00 (1,950 rows)documentary— mean 3.73, median 4.00 (675 rows)horror— mean 3.60, median 3.50 (832 rows)comedy— mean 3.60, median 3.50 (1,330 rows)drama— mean 3.57, median 3.50 (843 rows)animation— mean 3.54, median 3.50 (459 rows)
Top to bottom that is 3.96 against 3.41, a spread of 16.1%. The pooled average is 3.62.
select genre,
count(*) as rows,
round(avg(rating)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by rating) as median
from movie_ratings
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.