Skip to content
simstat.com Statistics by simulation

Frequency distribution calculator: table and histogram

This frequency distribution calculator groups a list of numbers into equal-width classes and builds the full frequency table: class limits, class boundaries, midpoints, frequency, relative frequency, cumulative frequency and cumulative relative frequency, with a histogram and a CSV download. Choose the number of classes or the class width, and it shows how the width was found. Everything runs in your browser.

Separate values with commas, spaces or new lines (so do not use commas as thousands separators). Type the values as recorded: 21.0 counts as one decimal place. The example is the fuel consumption, in miles per US gallon, of the 32 cars in the mtcars data that ship with R (from the 1974 Motor Trend US magazine).

Set

Leave empty for the suggested number from Sturges' rule: 6.

At or below the smallest value.

Automatic uses the most decimal places typed in the data, width or first limit. Choose more if values were recorded more precisely than typed.

Frequency table

Values n
32
Minimum to maximum
10.4 to 33.9
Classes
6
Class width
4.0

Class width, step by step

  1. Smallest value 10.4, largest 33.9, n = 32. Precision unit: 0.1 (1 decimal place).
  2. Number of classes k = 6 (Sturges: ⌈log₂(32) + 1⌉ = 6).
  3. Range = 33.9 − 10.4 = 23.5.
  4. Range ÷ k = 23.5 ÷ 6 ≈ 3.9167.
  5. Round up to the next multiple of 0.1: width = 4.0.
Grouped frequency distribution
Class Class limits Class boundaries Midpoint Frequency Relative frequency Cumulative frequency Cumulative relative frequency
1 10.4–14.3 10.35–14.35 12.35 4 0.1250 4 0.1250
2 14.4–18.3 14.35–18.35 16.35 10 0.3125 14 0.4375
3 18.4–22.3 18.35–22.35 20.35 9 0.2813 23 0.7188
4 22.4–26.3 22.35–26.35 24.35 4 0.1250 27 0.8438
5 26.4–30.3 26.35–30.35 28.35 1 0.0313 28 0.8750
6 30.4–34.3 30.35–34.35 32.35 4 0.1250 32 1.0000
Total 32

Relative frequencies are rounded to 4 decimals, so they may not add to exactly 1; cumulative relative frequencies are computed from the cumulative counts, so the last one is exactly 1.

Histogram of the frequency distribution Histogram of 32 values in 6 classes of width 4.0, from 10.35 to 34.35. The tallest bar is the class 14.4–18.3, with 10 values. The table gives every count. 0246810410941410.3514.3518.3522.3526.3530.3534.35Class boundaries
Bars stand on the class boundaries, so they touch; bar height is the frequency, printed above each bar. The table above gives the same counts.

What a frequency distribution is

A frequency distribution lists the values a variable takes, or groups of them, with how often each occurs. In the words of Illowsky and Dean (2023), "A frequency is the number of times a value of the data occurs", and a relative frequency is that count as a proportion of all outcomes. Measurements rarely repeat exactly, so you group them into classes of equal width and count the values in each: a grouped frequency distribution, drawn as a histogram.

How many classes: Sturges' rule

k=⌈log⁡2n+1⌉k = \lceil \log_2 n + 1 \rceil

Sturges' rule sets the number of classes k from the number of values n. It is R's default: the documentation of hist() gives "Sturges" as the default for the breaks, computed by nclass.Sturges as above (R Core Team, n.d.). R treats that number as a suggestion only and moves the breaks to "pretty" values, so hist() does not always draw exactly k classes. For n = 32 it gives k = ⌈5 + 1⌉ = 6, the calculator's suggestion.

Treat it as a starting point. Sturges (1926, as cited by Hyndman, 1995) derived the rule from an idealised histogram whose bar heights are binomial coefficients. Hyndman (1995) argues that "the argument leading to Sturges' rule is wrong", and notes that the rule is known to oversmooth, especially in large samples. For moderate n (less than 200) it gives results similar to better-founded rules; "However, it does not work for large n." It grows slowly: 11 classes for 1,000 values, 21 for 1,000,000. Illowsky and Dean (2023) note that "Many histograms consist of five to 15 bars or classes for clarity." Try a few values of k.

Class width and the rounding rule

w=(⌊max⁡−min⁡k u⌋+1)uw = \left( \left\lfloor \frac{\max - \min}{k\,u} \right\rfloor + 1 \right) u

Here u is the precision unit of the data: 1 for whole numbers, 0.1 for one decimal place, 0.01 for two. In words: divide the range, max − min, by k and round up to the next unit; if the division already gives a whole number of units, add one unit. If you set a first lower limit s below the minimum, the calculator uses max − s in place of the range. The calculator shows each step.

Both parts of the rule make the classes reach the maximum. Jones (n.d.), writing about whole numbers, gives the condition: "The starting point plus the number of classes times the class width must be greater than the maximum value." For whole numbers from 20 to 50 in 6 classes, the range divided by k is exactly 5. Classes of width 5 starting at 20 would end at 49 and miss the maximum, so the rule gives 6. For this case Jones notes that "you can either add one to the number of classes or add one to the class width"; the calculator keeps your k. Geraghty (n.d.) divides max − min + 1 by k and rounds up (to a convenient value), which for whole numbers gives the same width: his example, 67 to 125 in 5 classes, gives 12 either way. The formula above applies the same test in units of the data's precision.

For round class limits, set the width and the first lower limit yourself: with width 5.0 from 10.0, the default data need 5 classes, the first running from 10.0 to 14.9.

Class limits, boundaries and midpoints

Li=s+(i−1) w,Ui=Li+w−u,mi=Li+Ui2L_i = s + (i - 1)\,w, \qquad U_i = L_i + w - u, \qquad m_i = \frac{L_i + U_i}{2}
boundaries: Li−u2  and  Ui+u2\text{boundaries: } L_i - \tfrac{u}{2} \ \text{ and } \ U_i + \tfrac{u}{2}

The class limits are the smallest and largest values a class can hold at the data's precision. The first lower limit s is the minimum unless you choose a lower one; each next lower limit adds the width; each upper limit is the next lower limit minus one unit (Jones, n.d.: "subtract one from the lower limit of the second class"). The boundaries lie half a unit outside the limits, halfway between one class and the next, so the classes join without gaps. Carrying them to one more decimal place than the data means that, in Illowsky and Dean's (2023) words, "no data value will fall on a boundary." The midpoint, (lower limit + upper limit)/2, is the centre of the class.

Relative and cumulative frequency

relativei=fin,Fi=f1+⋯+fi,cumulative relativei=Fin\text{relative}_i = \frac{f_i}{n}, \qquad F_i = f_1 + \dots + f_i, \qquad \text{cumulative relative}_i = \frac{F_i}{n}

The relative frequency is a class's count divided by n (times 100, a percentage). The cumulative frequency adds the counts up to and including the class: how many values are at or below its upper limit. Divided by n, it is the cumulative relative frequency. Illowsky and Dean (2023) warn that "Because of rounding, the relative frequency column may not always sum to one". The calculator divides the cumulative counts by n instead of adding rounded values, so the last entry is exactly 1. The table and the CSV file include both columns.

Worked example

Worked example: mtcars fuel consumption

The data are the fuel consumption of the 32 cars in R's mtcars data set, in miles per US gallon, recorded to one decimal, so the unit is 0.1. Sturges' rule gives k = 6 classes. The smallest value is 10.4 and the largest 33.9, so the range is 23.5, and 23.5 ÷ 6 ≈ 3.9167. Rounded up to the next 0.1, the class width is 4.0.

The first class has limits 10.4 and 14.3 (the next lower limit, 14.4, minus 0.1), boundaries 10.35 and 14.35, and midpoint 12.35. It holds 4 cars, a relative frequency of 4/32 = 0.1250. The second class, 14.4–18.3, holds 10 cars (0.3125), so 14 cars (cumulative relative frequency 0.4375) get at most 18.3 miles per gallon. The last class, 30.4–34.3, contains the maximum; its cumulative frequency is 32, all the cars.

These are the calculator's defaults: the table above shows every class.

Reading the histogram and reporting the table

A histogram "consists of contiguous (adjoining) boxes" (Illowsky and Dean, 2023): the bars stand on the class boundaries, so they touch. The NIST/SEMATECH e-Handbook lists what it shows: where the data are located, how spread out they are, whether they are symmetric or skewed, and whether there are outliers. For the default data, the tallest bar is 14.4–18.3, and the bars stretch further to its right than to its left. The picture depends on the classes, so say how you chose them:

Fuel consumption of the 32 cars ranged from 10.4 to 33.9 mpg. Grouped into 6 classes of width 4.0 (Sturges' rule, starting at the minimum), the most common class was 14.4–18.3 mpg, with 10 cars (31.25%).

For the working by hand, read our guides on how to find class width and how to find class boundaries, limits and midpoints.

To count words rather than numbers, use our word frequency counter. To watch a histogram of sample means take shape, try the sampling distribution simulator and our guide to the sampling distribution. More tools are on the statistics hub.

References

  • Geraghty, M. A. (n.d.). 2.5.3: Grouping numeric data. In Inferential Statistics and Probability: A Holistic Approach. LibreTexts. stats.libretexts.org
  • Henderson, H. V. & Velleman, P. F. (1981). Building multiple regression models interactively. Biometrics, 37(2), 391–411. doi.org/10.2307/2530428 (source of the mtcars data, as cited by R's documentation)
  • Hyndman, R. J. (1995). The problem with Sturges' rule for constructing histograms. Monash University. robjhyndman.com/papers/sturges.pdf
  • Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, sections 1.3 and 2.2. OpenStax.
  • Jones, J. (n.d.). Statistics: Grouped frequency distributions. Math 170 lecture notes, Richland Community College. people.richland.edu
  • NIST/SEMATECH. e-Handbook of Statistical Methods, section 1.3.3.14, Histogram. itl.nist.gov
  • R Core Team (n.d.). Histograms (hist), Compute the number of classes for a histogram (nclass.Sturges) and Motor Trend car road tests (mtcars). R documentation: hist, nclass.Sturges, mtcars.