Statistics · 9 min read
Understanding Frequency Distributions
How absolute, relative and cumulative frequencies are built, how to choose class widths with Sturges, Scott and Freedman–Diaconis, and why discrete and continuous data need different treatment.
Introduction
A frequency distribution answers the most basic question you can ask of a set of measurements: which values occur, and how often? Before you compute a mean, fit a model or compare two periods, it is worth looking at the shape of the data. Is it symmetric or skewed? Is there one peak or several? Are there isolated values far from the rest? A frequency table and its graphical counterpart, the histogram, show all of this at a glance.
Building a frequency distribution looks trivial, but it involves real decisions. For discrete data you must decide whether to show every value. For continuous data you must choose class boundaries and a class width, and that choice can change what the chart appears to say. This article walks through the vocabulary, the arithmetic and the standard bin-width rules, using small datasets you can check by hand.
Absolute, relative and cumulative frequency
Suppose a dataset of n observations has been divided into classes (also called bins). Four quantities are reported for each class:
- Absolute frequency (fᵢ)
- The number of observations that fall into class i. The absolute frequencies sum to n.
- Relative frequency (rᵢ)
- The share of all observations in class i: rᵢ = fᵢ / n. Relative frequencies sum to 1 (or 100%) and make datasets of different sizes comparable.
- Cumulative frequency (Fᵢ)
- The number of observations in class i and all classes below it: Fᵢ = f₁ + f₂ + … + fᵢ. The last cumulative frequency equals n.
- Cumulative relative frequency (Rᵢ)
- Fᵢ / n, the share of observations at or below the upper boundary of class i. Plotted against the upper boundaries, it gives the empirical cumulative distribution (an ogive).
Worked example: items per order
Twenty sampled orders contained the following numbers of items: 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 6. The data are discrete (whole items), so each integer value forms its own class.
| Items | Absolute f | Relative r | Cumulative F | Cumulative relative R |
|---|---|---|---|---|
| 1 | 6 | 0.30 | 6 | 0.30 |
| 2 | 7 | 0.35 | 13 | 0.65 |
| 3 | 4 | 0.20 | 17 | 0.85 |
| 4 | 2 | 0.10 | 19 | 0.95 |
| 5 | 0 | 0.00 | 19 | 0.95 |
| 6 | 1 | 0.05 | 20 | 1.00 |
Several facts can be read straight from the table: 65% of orders contain at most two items, 95% contain at most four, and the single six-item order sits apart from the rest. The empty row for five items is deliberate. Omitting empty classes would visually close the gap and misrepresent the shape of the distribution.
Discrete versus continuous data
The distinction matters because it determines how classes should be formed.
- Discrete data take separate, countable values: items in an order, defects per batch, visits per day. When the number of distinct values is moderate, one class per value is the most honest representation. In the Insider Magazin workspace each integer k gets the class [k − 0.5, k + 0.5), so the bar is centred on the value itself and adjacent bars touch without overlapping.
- Continuous data can in principle take any value within a range: response times, energy demand, temperatures. Values are recorded with finite precision (for example one decimal), but with hundreds of observations almost every recorded value is unique, so a table of individual values is useless. The values must be grouped into intervals.
Some data sit in between. Counts with a very wide range (page views per day, for instance) are technically discrete but behave like continuous data for summarizing purposes. For such cases the workspace falls back to grouped classes when the integer range is too wide to show one bar per value.
Class boundaries
Grouped classes need an unambiguous rule for values that land exactly on a boundary. The usual convention, and the one used in the workspace, is half-open intervals [a, b): the lower edge is included, the upper edge is excluded. The final class also includes its upper edge so that the maximum is never dropped. Whatever the convention, it should be stated and applied consistently, especially when data are recorded with coarse precision and many values coincide with round numbers.
Choosing a class width
The class width h controls a trade-off. Narrow classes follow the data closely but produce a jagged histogram in which random noise looks like structure. Wide classes produce a smooth picture but can hide real features such as a second peak or a gap. Three classical rules give a principled starting point.
Sturges' rule
Sturges' rule is derived from the binomial distribution and implicitly assumes roughly bell-shaped data. It is simple and works well for small samples, but the number of classes grows very slowly: about 8 classes for n = 100, 11 for n = 1,000 and 15 for n = 10,000. For large or skewed datasets it tends to oversmooth.
Scott's rule
Scott's rule minimizes the integrated mean squared error of the histogram as a density estimate when the data are normally distributed. Because it uses the standard deviation, it is sensitive to outliers and heavy tails: a few extreme values inflate s and therefore the class width.
Freedman–Diaconis rule
The Freedman–Diaconis rule replaces the standard deviation with the interquartile range, which is barely affected by extreme values. That makes it a robust default for real-world data, and it is the default in the Insider Magazin histogram. For normally distributed data the IQR is about 1.349σ, so Freedman–Diaconis gives roughly 2.70σ · n^(−1/3), somewhat narrower than Scott. Both rules share the n^(−1/3) factor: multiplying the sample size by 8 halves the class width.
If the IQR is zero (for example, when more than half of the values are identical), the Freedman–Diaconis width would be zero. The workspace then falls back to Sturges.
Rounding to readable edges
Raw widths such as 3.684 make poor axis labels. The workspace rounds the computed width up to the next value of the form 1, 2, 2.5 or 5 × 10ᵏ, and starts the first class at a multiple of that width at or below the minimum. Because the width is rounded up, the histogram usually ends up with the same number of classes the rule implies or a few fewer; aligning the first edge to a round number can add one class at the ends of the range.
Worked example: three rules on the same data
Consider twenty first-response times in minutes, already sorted: 4.2, 5.1, 5.8, 6.3, 6.9, 7.4, 7.7, 8.1, 8.6, 9.0, 9.4, 9.9, 10.5, 11.2, 12.0, 13.1, 14.8, 16.5, 19.7, 27.3. The summary statistics needed by the rules are: n = 20, range = 27.3 − 4.2 = 23.1, sample standard deviation s ≈ 5.537, Q1 = 7.275 and Q3 = 12.275 (type-7 quantiles), so IQR = 5.0. The cube root factor is 20^(−1/3) ≈ 0.3684.
| Rule | Computation | Raw width | Rounded width | Classes |
|---|---|---|---|---|
| Sturges | k = ⌈4.32⌉ + 1 = 6; 23.1 / 6 | 3.85 | 5 | 6 |
| Scott | 3.49 × 5.537 × 0.3684 | 7.12 | 10 | 3 |
| Freedman–Diaconis | 2 × 5.0 × 0.3684 | 3.68 | 5 | 6 |
With a width of 5 the classes are [0, 5), [5, 10), [10, 15), [15, 20), [20, 25) and [25, 30], with counts 1, 11, 5, 2, 0 and 1. The histogram shows a clear peak between 5 and 10 minutes, a right tail, and one isolated long response. With Scott's width of 10, the classes [0, 10), [10, 20) and [20, 30] hold 12, 7 and 1 observations: the shape is still right-skewed, but the gap before 27.3 has disappeared.
Scott's width is larger here because the single value 27.3 inflates the standard deviation, while the IQR used by Freedman–Diaconis ignores it. This is exactly the situation in which a robust rule earns its place. Note also that on such a small sample, the rounding step dominates: Sturges and Freedman–Diaconis produce different raw widths but the same final classes.
Counts, relative frequencies and densities
A histogram's vertical axis can show three different quantities, and choosing the right one depends on the comparison you want to make.
- Count: the absolute frequency. Intuitive, but only comparable between histograms built from the same number of observations.
- Relative frequency: fᵢ / n. Use this when comparing groups or periods of different sizes. Bar heights sum to 1.
- Density: rᵢ / h, relative frequency divided by class width. The areas of the bars sum to 1, so histograms with different class widths can be overlaid, and the result is directly comparable to a probability density curve.
In the response-time example, the class [5, 10) has relative frequency 11 / 20 = 0.55 and density 0.55 / 5 = 0.11 per minute. If you rebuilt the histogram with a width of 2.5, the bar heights in density units would stay on a comparable scale even though the counts per class would roughly halve.
Common pitfalls
Read the bins before you read the shape
A histogram is a summary that depends on the class width and the position of the first edge. Before drawing conclusions, try at least one alternative width. Features that survive a change of bin width (a second peak, a long tail, a gap) are likely real; features that appear and disappear are likely artefacts of binning.
- Comparing raw counts across groups of different size. A category with twice as many observations will have taller bars everywhere. Compare relative frequencies, and use identical class edges for every group; the workspace's distribution comparison does both.
- Unequal class widths shown as counts. If classes have different widths, wide classes look artificially important. Use density, or keep widths equal.
- Treating discrete data as continuous. Grouping integers into classes such as [0, 2.5) and [2.5, 5) puts two values in one bar and three in the next, producing a saw-tooth pattern that has nothing to do with the data.
- Over-reading small samples. With twenty observations, a single value moving across a boundary changes a relative frequency by five percentage points.
- Ignoring recording precision. Values rounded to whole minutes will pile up on boundaries if class edges are whole numbers. Be explicit about which side the boundary belongs to.
Frequency distributions in the workspace
The histogram view lets you switch between Freedman–Diaconis, Sturges, Scott and a fixed number of bins, and between count, relative frequency and density. The frequency table reports absolute, relative, cumulative and cumulative relative frequency for each class and can be exported as CSV. For a view over time, the frequency-by-period heatmap shows relative frequencies per year or quarter, so each period sums to 100% regardless of how many observations it contains.
To try the rules on real-looking data, open the interactive demo and switch bin rules on one of the illustrative datasets. The exact formulas and conventions are listed in the methodology, and the documentation explains each view step by step.