Skip to content
Tutorials Center
My learning

Topics

Lesson 7 of 57 ยท Describing Data

Frequency Tables and Grouped Data

Build frequency, relative frequency and cumulative tables, group continuous data into class intervals, and estimate the mean from grouped data with the direct and step-deviation methods.

A list of 500 numbers is hard to read. A frequency table compresses it into a few rows that show how often each value, or range of values, occurs. It is the first step toward histograms and the way many published datasets arrive, already grouped. This lesson shows how to build one and how to compute a mean when you only have the table.

Frequency, relative and cumulative frequency

Take 20 quiz scores out of 10. Counting how many students got each score gives:

Score Frequency (f) Relative frequency Cumulative frequency
5 2 0.10 2
6 4 0.20 6
7 6 0.30 12
8 5 0.25 17
9 3 0.15 20
  • Frequency: the count.
  • Relative frequency: the count divided by the total (a proportion; times 100 gives a percentage).
  • Cumulative frequency: a running total, useful for medians and percentiles.
Python Build a frequency table

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Grouping continuous data into classes

For continuous data (heights, waiting times) almost every value is unique, so you group values into class intervals. Some guidelines:

  1. Use roughly 5 to 15 classes. Sturges' rule suggests k = 1 + log2(n).
  2. Make the classes the same width, covering the whole range without overlap.
  3. Decide how to treat boundaries. The common convention is that a class includes its lower limit but not its upper one, e.g. [10, 20).

The class midpoint is the average of a class's two limits and represents every value in the class.

Python Grouped frequency with NumPy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

NumPy's histogram uses half-open intervals except the last bin, which also includes its upper edge. That is exactly the convention above.

Mean of grouped data

Once the original values are gone, you estimate the mean by assuming every value sits at its class midpoint m:

mean โ‰ˆ sum(f * m) / sum(f)

This is the direct method. The result is an approximation, because grouping loses detail.

Assumed mean method

Large midpoints make the arithmetic tedious. Choose an assumed mean A (any convenient midpoint near the center), compute deviations d = m - A, and use

mean = A + sum(f * d) / sum(f)

Step-deviation method

If all class widths equal h, divide the deviations by h: u = (m - A) / h. Then

mean = A + h * sum(f * u) / sum(f)

All three give the same answer; the shortcuts exist to keep hand calculation small. A computer makes the direct method easy.

Python Three ways to the same mean

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

All three print 19.5, the same value.

Median and mode from grouped data

Locate the median class, the first class whose cumulative frequency reaches n/2. Then interpolate inside it:

median = L + ((n/2 - C) / f) * h

where L is the lower limit of the median class, C the cumulative frequency before it, f its frequency and h its width. The modal class is the one with the highest frequency; an estimate is

mode = L + ((f1 - f0) / (2*f1 - f0 - f2)) * h

with f1 the modal frequency and f0, f2 its neighbors.

Python Median and mode of grouped data

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reading a frequency distribution

A good table makes patterns visible: where the bulk lies, whether it is symmetric, whether there are gaps or isolated extreme classes. When the data are categories, order the rows by frequency (a Pareto layout) to put the most common first.

flowchart LR
    R["Raw data<br/>20 values"] --> T["Frequency table<br/>5 classes"]
    T --> H["Histogram"]
    T --> G["Grouped mean,<br/>median, mode"]

Grouping trades detail for readability; never discard the raw data if you can keep it.

Common mistakes

  • Overlapping classes such as 10-20 and 20-30: a value of 20 would be counted twice.
  • Unequal widths without adjusting for them. Histograms of unequal classes must plot density, not raw counts.
  • Treating the grouped mean as exact. It is an estimate.

You will see how to draw these tables in visualizing distributions.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In a table of 40 values, one class has frequency 10. Its relative frequency is...

    10 / 40 = 0.25, or 25 percent.
  2. 2. Why do we use class midpoints for the grouped mean?

    Without the raw values, we assume everything in a class sits at its midpoint.
  3. 3. Midpoints 5, 15, 25 have frequencies 2, 6, 2. What is the grouped mean?

    (25 + 615 + 2*25) / 10 = 150 / 10 = 15.
  4. 4. Which cumulative frequency is used to find the median class?

    The median class contains the middle observation.

Summary

  • Frequency tables show counts, relative frequencies and running totals.
  • Continuous data are grouped into equal-width, non-overlapping class intervals.
  • The grouped mean uses midpoints: direct, assumed mean and step-deviation methods agree.
  • Median and mode of grouped data come from interpolation inside the median and modal classes.
  • Grouping loses detail, so grouped statistics are estimates.

Next: Variance and Standard Deviation