Field note · June 9, 2025
fare_usd by payment_type: a 4% spread
Real group means for one column across 3 segments, and what the pooled average conceals.
Breaking fare_usd down by payment_type on ride-hail-trips, because the headline average is 22.16 and no segment is actually there.
cash— mean 22.93, median 14.51 (892 rows)card— mean 22.12, median 14.39 (4,983 rows)wallet— mean 21.95, median 14.03 (2,125 rows)
Top to bottom that is 22.93 against 21.95, a spread of 4.4%. The pooled average is 22.16.
select payment_type,
count(*) as rows,
round(avg(fare_usd)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by fare_usd) as median
from ride_hail_trips
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 most in cash, where the mean sits well above the median. 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.