Field note · May 18, 2023
baseline_score by arm: a 0% spread
Real group means for one column across 2 segments, and what the pooled average conceals.
Breaking baseline_score down by arm on clinical-trial, because the headline average is 61.14 and no segment is actually there.
treatment— mean 61.28, median 61.35 (450 rows)placebo— mean 61.00, median 61.30 (450 rows)
Top to bottom that is 61.28 against 61.00, a spread of 0.5%. The pooled average is 61.14.
select arm,
count(*) as rows,
round(avg(baseline_score)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by baseline_score) as median
from clinical_trial
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.