TExcelTAD
Home › Statistics › Range

Range

The range is the simplest measure of variation: the distance between the largest and the smallest value.

text
range = maximum − minimum

It answers the question "how far apart are the extremes?" in the units of the data.

Computing the range

The daily high temperatures (°C) in a mountain town during one week:

python · try it yourself
highs = [14, 9, 17, 21, 12, 8, 16]

lowest, highest = min(highs), max(highs)
print("min   =", lowest)
print("max   =", highest)
print("range =", highest - lowest)
min   = 8
max   = 21
range = 13

NumPy has a dedicated function, np.ptp ("peak to peak"), and in pandas you subtract min() from max(), which also works per group:

python · try it yourself
import numpy as np
import pandas as pd

highs = np.array([14, 9, 17, 21, 12, 8, 16])
print("np.ptp:", np.ptp(highs))

weather = pd.DataFrame({
    "town": ["Alpine"] * 4 + ["Seaside"] * 4,
    "high": [14, 9, 21, 8, 18, 19, 17, 20],
})
by_town = weather.groupby("town")["high"].agg(["min", "max"])
by_town["range"] = by_town["max"] - by_town["min"]
print(by_town)
np.ptp: 13
         min  max  range
town
Alpine     8   21     13
Seaside   17   20      3

The Seaside temperatures vary within 3 degrees, the Alpine ones within 13.

Strengths

  • Very easy to compute and to explain.
  • Directly meaningful in many settings: tolerances in manufacturing ("every part must be within a 0.2 mm range"), the spread of prices for the same product, or the daily price swing of a stock.

Weaknesses

It depends on only two values

The range ignores everything between the extremes. These two datasets have the same range, yet look completely different:

python · try it yourself
import statistics

clustered = [10, 50, 50, 50, 50, 50, 50, 90]
spread_out = [10, 20, 30, 40, 60, 70, 80, 90]

for name, x in [("clustered", clustered), ("spread out", spread_out)]:
    print(f"{name:11s} range={max(x) - min(x)}  stdev={statistics.stdev(x):.2f}")
clustered   range=80  stdev=21.38
spread out  range=80  stdev=29.28

It is very sensitive to outliers

A single unusual value can multiply the range:

python · try it yourself
reaction_ms = [231, 245, 228, 252, 240, 236, 249, 243]
print("range:", max(reaction_ms) - min(reaction_ms))

reaction_ms.append(910)        # the participant sneezed
print("range with one outlier:", max(reaction_ms) - min(reaction_ms))
range: 24
range with one outlier: 682

It grows with sample size

The more values you collect, the more likely you are to catch a rare extreme. So ranges from samples of different sizes are not directly comparable, even when the samples come from the same population:

python · try it yourself
import numpy as np

rng = np.random.default_rng(30)
for n in [10, 100, 1000, 10_000]:
    sample = rng.normal(170, 8, size=n)        # heights in cm from the same population
    print(f"n={n:6d}: range = {np.ptp(sample):5.1f} cm,  std = {sample.std(ddof=1):4.2f} cm")
n=    10: range =  26.7 cm,  std = 8.94 cm
n=   100: range =  37.9 cm,  std = 7.76 cm
n=  1000: range =  63.1 cm,  std = 8.02 cm
n= 10000: range =  62.9 cm,  std = 7.90 cm

The standard deviation stays near 8 cm for every sample size, but the range more than doubles, from about 27 cm with 10 people to about 63 cm with a thousand or more. (Its growth slows down for large samples, and a single sample can buck the trend, but unlike the standard deviation it never settles at a fixed value.) That makes the standard deviation (or the IQR) a better general-purpose measure of spread.

Tip: Report the range together with the minimum and maximum ("from 8 °C to 21 °C") rather than as a single number. Readers learn more from the two extremes than from their difference.

Test yourself

What is the range of 7, 3, 12, 9, 5?

  1. 5
  2. 7
  3. 9
  4. 12

Why is the range a poor measure of spread for data with outliers?

  1. It is hard to compute
  2. It is determined entirely by the two most extreme values
  3. It ignores the minimum
  4. It is always zero

You draw bigger and bigger samples from the same population. What usually happens to the sample range?

  1. It stays about the same
  2. It tends to grow
  3. It tends to shrink
  4. It becomes equal to the standard deviation