Course contentsShow
← Data Science
Lesson 1385 of 2,14535. Statistical Anomaly DetectionFree lesson

Calculating IQR Fences in Practice

Compute lower and upper fences step-by-step to flag potential outliers in real datasets.

Calculating IQR Fences in Practice

You'll learn: How to compute the exact lower and upper fence values that separate typical data points from potential outliers using the IQR method.

Now that you understand the IQR outlier detection rule, let's walk through the calculation step-by-step. The process is straightforward but requires precision.

The Four-Step Calculation

Step 1: Find Q1 and Q3
Calculate the first quartile (25th percentile) and third quartile (75th percentile) of your dataset.

Step 2: Calculate IQR
Subtract Q1 from Q3: IQR = Q3 - Q1

Step 3: Compute the Fences

  • Lower fence = Q1 - 1.5 × IQR
  • Upper fence = Q3 + 1.5 × IQR

Step 4: Flag Outliers
Any data point below the lower fence or above the upper fence is a potential outlier.

A Concrete Example

Imagine analyzing customer purchase amounts: [10, 12, 14, 15, 18, 20, 22, 95]

  • Q1 = 13 (25th percentile)
  • Q3 = 21 (75th percentile)
  • IQR = 21 - 13 = 8
  • Lower fence = 13 - 1.5(8) = 13 - 12 = 1
  • Upper fence = 21 + 1.5(8) = 21 + 12 = 33

The value 95 exceeds the upper fence of 33, so it's flagged as a potential outlier—perhaps a bulk order or data entry error.

Think of It Like a Safe Zone

The fences act like guardrails on a highway. The IQR defines the "normal" traffic pattern, and the 1.5× multiplier extends a reasonable buffer zone. Anything beyond those guardrails warrants investigation.

Key Takeaway: Computing IQR fences involves finding Q1 and Q3, calculating the IQR, then applying the 1.5× multiplier to set lower and upper boundaries that flag values falling outside the typical data range.