Field note · July 19, 2025

distance_km by payment_type: a 3% spread

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

1 min read ·Analytics practice ·statistics practice

Breaking distance_km down by payment_type on ride-hail-trips, because the headline average is 4.83 and no segment is actually there.

  • card — mean 4.87, median 3.19 (4,983 rows)
  • wallet — mean 4.78, median 3.27 (2,125 rows)
  • cash — mean 4.74, median 3.16 (892 rows)

Top to bottom that is 4.87 against 4.74, a spread of 2.9%. The pooled average is 4.83.

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