Field note · August 10, 2023
temp_c by site: a 3% spread
Real group means for one column across 3 segments, and what the pooled average conceals.
Breaking temp_c down by site on sensor-telemetry, because the headline average is 41.42 and no segment is actually there.
NOR— mean 42.24, median 42.01 (2,823 rows)RIV— mean 41.17, median 41.12 (2,355 rows)SLT— mean 40.82, median 40.73 (2,822 rows)
Top to bottom that is 42.24 against 40.82, a spread of 3.5%. The pooled average is 41.42.
select site,
count(*) as rows,
round(avg(temp_c)::numeric, 2) as mean,
percentile_cont(0.5) within group (order by temp_c) as median
from sensor_telemetry
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.