Tutorials › Exam PA - Predictive Analytics › How Histogram Bin Width Changes the Story

Exam PA · Visualization and Anomaly Detection · Tutorial 134 of 966

How Histogram Bin Width Changes the Story

See how bin width and break placement shape a histogram, and learn to check whether apparent patterns persist under reasonable alternatives.

Beginner 10 min read

What You'll Learn

  • Explain why wider bins smooth detail while narrower bins can expose local variation.
  • Compare histograms with equal widths but different starting breaks.
  • Calculate histogram counts and density heights, including for unequal-width bins.
  • Specify break vectors and boundary conventions in R.
  • Assess whether apparent clusters, gaps, or extremes depend on binning.

Why the Same Data Can Tell Different Visual Stories

A histogram groups numeric observations into intervals and displays how many observations fall in each interval, or a scaled version of those counts. The observations do not change when the bins change, but the visual pattern can. A wide bin can combine values that would appear separated with narrower bins; a narrow bin can leave empty spaces between groups that a wider bin would combine. Even with the same bin width, shifting the break locations can change which values are counted together.

This matters in exploratory analysis because a histogram is a summary, not a direct picture of every observation. A cluster, gap, or isolated bar is a reason to examine the data and context, not proof that the underlying population has a distinct group or that an observation is erroneous. A useful first check is to compare a small number of reasonable widths and break locations while keeping the data and horizontal scale fixed.

Definition: A histogram bin is an interval of values, and its bin width is the length of that interval. With equal-width bins, a count histogram uses the number of observations in each interval as the bar height. A histogram's breaks are the boundaries separating its bins. The width controls how much data are pooled together; the break locations control where that pooling begins and ends.

Changing Width and Moving the Breaks

Consider a hypothetical set of 12 claim-processing times, in days: 1, 2, 3, 8, 9, 10, 11, 12, 18, 19, 20, 21. Use right-closed intervals: except for the first interval, a bin includes its right boundary but not its left boundary. The first bin also includes its lowest boundary. This matches the convention in base R when using right=TRUE and include.lowest=TRUE.

With breaks at 0, 10, 20, and 30, the three bins contain 6, 5, and 1 observations. With breaks at 0, 5, 10, 15, 20, 25, and 30, the six counts are 3, 3, 2, 3, 1, and 0. The narrower bins show more local variation, including a final empty interval, but that empty interval does not mean the data have a meaningful boundary at 25.

Now keep the width at 10 days and shift the breaks to -5, 5, 15, 25, and 35. The counts are 3, 5, 4, and 0. The break shift changes the appearance even though the width is unchanged. For example, the values 8, 9, 10, 11, and 12 are together in the bin (5, 15], whereas the earlier width-10 breaks placed the first three in [0, 10] and the last two in (10, 20]. A reader should therefore be cautious about treating a bar boundary as a real separation in the data.

In R, an explicit vector of breaks makes the intended boundaries clear. For example, hist(x, breaks=c(0, 10, 20, 30), right=TRUE, include.lowest=TRUE) sets the width-10 intervals for a vector x. A call such as hist(x, breaks=6) asks R for a number of breaks, not necessarily six bins of a specified width starting at a specified value. If exact width and origin matter to the comparison, supply the break vector and check the returned breaks.

Worked Example: Comparing Widths and Break Origins

A hypothetical insurer records claim-processing times x = c(1, 2, 3, 8, 9, 10, 11, 12, 18, 19, 20, 21). Compare the counts using width 10 with breaks 0, 10, 20, 30; width 5 with breaks 0, 5, 10, 15, 20, 25, 30; and width 10 shifted to -5, 5, 15, 25, 35. State what can and cannot be concluded. Use right=TRUE and include.lowest=TRUE. The method is to assign each value to exactly one interval; this avoids treating a break as if it were a boundary in the data.

Width 10, breaks 0, 10, 20, 30. The intervals are [0, 10], (10, 20], and (20, 30]. The first contains 1, 2, 3, 8, 9, 10, for a count of 6. The second contains 11, 12, 18, 19, 20, for a count of 5. The third contains 21, for a count of 1. The counts sum to 6 + 5 + 1 = 12.

Width 5, breaks 0, 5, 10, 15, 20, 25, 30. The six intervals have counts 3, 3, 2, 3, 1, and 0, respectively: [0, 5] contains 1, 2, 3; (5, 10] contains 8, 9, 10; (10, 15] contains 11, 12; (15, 20] contains 18, 19, 20; (20, 25] contains 21; and (25, 30] is empty. These counts sum to 3 + 3 + 2 + 3 + 1 + 0 = 12.

Width 10, shifted breaks. The intervals [-5, 5], (5, 15], (15, 25], and (25, 35] have counts 3, 5, 4, and 0. Their sum is 3 + 5 + 4 + 0 = 12. The same five values from 8 through 12 now occupy one bin, illustrating how a break shift can alter apparent concentration.

The narrower histogram makes the counts across neighboring bins more visible, while the two width-10 histograms combine observations differently because their breaks are positioned differently. None of these calculations establishes that the observations form distinct groups or that values near a boundary behave differently. The common mistake is to interpret an empty or tall bar as a data feature without checking whether it persists under a reasonable change in breaks.

Counts, Heights, and Unequal-Width Bins

With equal-width bins, count heights are easy to compare: each bar covers the same horizontal distance, so a taller bar represents more observations. If bin widths differ, raw counts alone can be misleading visually. A wider bar can cover more horizontal area simply because it is wider. In that setting, a density-scaled histogram uses a height that accounts for both the bin count and the total sample size.

$$ \text{density height for bin }j = \frac{n_j}{n w_j}, \qquad \text{bar area} = \frac{n_j}{n w_j}w_j = \frac{n_j}{n}. $$

Here \(n\) is the total number of observations, \(n_j\) is the number in bin \(j\), and \(w_j\) is that bin's width. The bar's area, not its height alone, represents the fraction of observations in that bin. This follows directly by multiplying the height by the bin width: the width cancels, leaving the bin count divided by the total count.

Worked Example: Reading Heights With Unequal Bin Widths

A hypothetical sample of 20 repair costs, measured in hundreds of dollars, is summarized in four right-closed bins. The bins (0, 5], (5, 10], (10, 20], and (20, 40] contain 4, 6, 8, and 2 observations, respectively. Find the density height for each bin and interpret the result. The method is to divide each bin's sample proportion by its width; this avoids mistaking a wide bar's area or a count for its height.

The sample size is \(n=4+6+8+2=20\). The bin widths are 5, 5, 10, and 20. The sample proportions are \(4/20=0.20\), \(6/20=0.30\), \(8/20=0.40\), and \(2/20=0.10\).

The density heights are therefore \(0.20/5=0.04\), \(0.30/5=0.06\), \(0.40/10=0.04\), and \(0.10/20=0.005\) per hundred dollars. Check the areas: \(0.04(5)=0.20\), \(0.06(5)=0.30\), \(0.04(10)=0.40\), and \(0.005(20)=0.10\). The total area is \(0.20+0.30+0.40+0.10=1.00\).

The bin with 8 observations has the largest count, but the bin with 6 observations has the greatest density height. That is not a contradiction: the latter bin is half as wide. In R, use hist(x, breaks=..., freq=FALSE) to request density-scaled heights, particularly when widths differ. The common mistake is to compare raw counts as though bar heights alone fairly represented bins of unequal width.

Why Bin Width Changes the Story

The basic trade-off is straightforward. Wider bins pool more observations, which can make broad patterns easier to see but conceal local variation. Narrower bins preserve more detail, but some bars may contain only a few observations or none. With a small sample, that extra fluctuation can look like a stable cluster or gap even when it is only a consequence of the chosen intervals.

Break location is a separate choice from width. Two histograms can use equal-width bins but differ because one begins at a different point. If a group of nearby observations falls on opposite sides of a boundary in one histogram, it may appear as two concentrations; shifting the boundary can put them in one bar. This is why comparisons should hold the horizontal range and width fixed when the goal is to compare groups, and should still be interpreted with awareness of the break origin.

Justification: For a density-scaled histogram, the height in bin \(j\) is the bin's sample proportion divided by its width. Multiplying that height by the width gives \(n_j/n\), the proportion of observations in that bin. Thus the area represents the bin's share of the sample even when widths differ. This area interpretation does not mean that a histogram reveals a unique underlying distribution; its appearance still depends on the selected bins.

For a practical comparison in R, begin by deciding what range should be displayed and use explicit break vectors when a particular width or origin is important. Then compare a few reasonable alternatives: for example, a wider and a narrower set of equal-width bins, and, if the origin might matter, a shifted set with the same width. Do not keep changing breaks until a preferred pattern appears. The purpose is to see whether an interpretation is robust, not to select the most persuasive-looking plot.

A change in binning can be especially important when assessing an apparent extreme. A value may occupy a bar by itself under one set of breaks and share a bar with other observations under another. That difference describes the display, not whether the value is plausible or erroneous. Check the recorded observation and its context before making a data-quality judgment; the histogram alone cannot decide that question.

1
Fix the data and scale.
Use the same observations and a consistent horizontal range so the comparison isolates binning choices.
2
Compare widths.
Use explicit breaks to see what broader pooling conceals and what narrower bins reveal.
3
Check the origin.
Shift the breaks without changing the width to see whether a cluster, gap, or isolated bar depends on boundary placement.
4
Describe cautiously.
Report patterns that are visible across reasonable choices, and distinguish those observations from conclusions that require checking the raw data or context.

Common Exam Traps

  • Comparing different widths as though counts were directly comparable. A bin twice as wide has more opportunity to contain observations. State the width and, for unequal widths, use density heights or compare bar areas.
  • Ignoring the break origin. Equal widths do not guarantee the same bin memberships. Check the actual break vector, not only the nominal width.
  • Overstating an empty bin. An empty interval means no observed values fell between those boundaries in this sample. It does not establish a population gap.
  • Calling an isolated bar an error or outlier. A solitary bar can result from the chosen breaks. A histogram is a visual summary, not a data-validation rule.
  • Assuming R's requested number of breaks gives exact widths. For a controlled comparison, provide the boundary vector and set the boundary convention explicitly.
Key takeaway: A histogram's appearance depends on both bin width and break location. Check whether a visual claim persists under reasonable alternatives, use density-scaled heights when widths differ, and do not treat a bin boundary or isolated bar as evidence by itself.

Check Your Understanding

For each problem, calculate or identify the effect of the stated binning choice before checking the answer.

  1. A sample is 2, 4, 6, 8, 12, 14, 16, 18. With breaks 0, 10, 20 and right-closed bins, what are the two counts? (Answer: 4 and 4.)
  2. For the same sample, use breaks 0, 5, 10, 15, 20. What are the four counts, including the empty-bin count if any? (Answer: 2, 2, 2, 2.)
  3. A bin has 5 observations in a sample of 25 and has width 4 units. What is its density height, and what is its area? (Answer: height 0.05 per unit; area 0.20.)
  4. Two histograms use width-10 bins. One has breaks 0, 10, 20, 30; the other has breaks 5, 15, 25, 35. What choice changed, and why can the counts change? (Answer: The break origin changed; observations near boundaries can be assigned to different bins.)
  5. A value appears alone in a bar when width is 5 but shares a bar with two other values when width is 15. What conclusion is justified about the value? (Answer: Only that its displayed bin membership depends on width; the histogram alone does not establish that it is erroneous or unusually extreme.)
Clinical Biostats