Field note · July 19, 2023
The overall average hides 6 different numbers
Real group means for one column across 6 segments, and what the pooled average conceals.
site splits clinical-trial into 6 groups. Here is what baseline_score looks like inside each.
site-6— mean 62.19, median 63.10 (146 rows)site-1— mean 61.92, median 62.95 (142 rows)site-4— mean 61.45, median 61.45 (152 rows)site-3— mean 61.04, median 60.75 (148 rows)site-2— mean 60.61, median 60.60 (174 rows)site-5— mean 59.67, median 58.90 (138 rows)
Top to bottom that is 62.19 against 59.67, a spread of 4.2%. The pooled average is 61.14.
select site,
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.