Unit 06.01: Histograms and the bin-width decision
Bin width is a modelling choice that decides what the reader concludes.
One group, two groups, or noise
The same bimodal data binned four ways.
The code counts the visible peaks at each width.
import numpy as np
rng = np.random.default_rng(1)
data = np.concatenate([rng.normal(20, 3, 200), rng.normal(35, 3, 200)])
print(f"{'bins':>6} {'peaks visible':>15} what the reader concludes")
for bins in (3, 8, 25, 100):
counts, _ = np.histogram(data, bins=bins)
peaks = sum(1 for i in range(1, len(counts) - 1)
if counts[i] > counts[i - 1] and counts[i] > counts[i + 1])
verdict = {3: "one group", 8: "two groups", 25: "two groups",
100: "noise"}[bins]
print(f"{bins:>6} {peaks:>15} {verdict}")
print("\nThe data is two distinct populations. At 3 bins that fact disappears.")
# Bin width is a modelling choice, not a display setting. Try several, and if
# the conclusion changes between them, say which you chose and why.
At three bins the data is one hump and the two populations have disappeared. At a hundred it is noise. Between those, the structure is clear.
The data did not change. The conclusion a reader draws changed completely, based on a setting that is usually left at whatever the tool chose.
The mistake this prevents
The mistake is accepting the default bin count. Try several, and if the conclusion changes between them, that is a finding - say which you chose and why, rather than presenting one as though it were the only view.
Takeaway
Try several bin widths and check whether the conclusion is stable. A histogram's default binning can hide a second population entirely.
