Skip to main content

IQR Outlier Fences

BeginnerData, Statistics & Computational SkillsAlso known as: data and coding workflow, data cleaning, Tukey fences, detect outliers, interquartile range

Finds: values that sit far outside the bulk of the data.

When to use it: Use it as a first pass in cleaning data, to find values that look like errors or extreme events, such as a price typed with an extra digit. Quartiles ignore extreme values, so one bad point cannot hide itself the way it can in a mean and standard deviation test. A flagged value is a prompt to investigate, not an instruction to delete: real crashes are outliers too.

The formula

IQR\displaystyle IQR=Q3−Q1\displaystyle =Q_{3}-Q_{1}Fences\displaystyle \text{Fences}=Q1−k⋅IQR,  Q3+k⋅IQR\displaystyle =Q_{1}-k\cdot IQR,\; Q_{3}+k\cdot IQR

In words: IQR = third quartile − first quartile; Lower fence = Q1 − k x IQR; Upper fence = Q3 + k x IQR; values outside the fences are flagged (k = 1.5 is the usual choice)

What each symbol means

Q_1, Q_325th and 75th percentiles of the datasame as data
IQRInterquartile range: the spread of the middle half of the datasame as data
kFence multiplier. 1.5 flags mild outliers, 3 flags extreme onesnumber

Worked example

Fifteen daily values are in the calculator. Which are outliers with k = 1.5?

First quartile (25th percentile)12.50
Third quartile (75th percentile)15.50
IQR15.5 − 12.53
Lower fence12.5 − 1.5 × 38
Upper fence15.5 + 1.5 × 320
Values outside the fences1
Mean with all values19.27
Mean without the flagged values13.86
The answer

The quartiles are 12.50 and 15.50, so the IQR is 3 and the fences are 8 and 20. 1 value lies outside, the 95. The mean is 19.27 with it and 13.86 without, which shows how much one point can move it.

Want every formula on a few pages?Get the free Cheat Sheet (PDF) →

Calculator

Lower fence8
Upper fence20
Values outside the fences1

Keep going