Find a course

Module 4: Duplicates, Outliers and ValidationLesson 9 of 1214 min

Outliers: Errors or Real Extremes?

Detect outliers with the IQR rule and z-scores, separate data errors from rare real values, and choose between correcting, capping, keeping and removing.

Step 1 of 10Learn

The $95 million house

A real estate website reported that the average home sold in a small town last year went for $2.1 million. Local agents were baffled; most homes there sell for $300,000 to $600,000. The culprit was a single record: a house sold for $950,000 had been typed as $95,000,000. Among about 50 sales, that one value multiplied the average roughly by four.

An outlier is a value far from the rest of the data. Some outliers are errors: a typo, a unit mix-up, a sentinel code like 99999. Others are real but rare: a billionaire in an income survey, a viral video in a list of view counts, a hurricane day in rainfall data. The statistics look the same, but the right response is opposite. Errors should be fixed. Real extremes should usually be kept, because they are often the most important values in the dataset.

So outlier handling has two steps that must not be merged: detect values that are unusual, then diagnose each one before acting. Detection is mechanical; you'll learn two standard rules for it. Diagnosis needs context: domain knowledge, source records and sometimes a phone call to whoever entered the data.

Step 2 of 10Learn

Detecting outliers: the IQR rule and z-scores

The IQR rule. Sort the data and find the first quartile Q1 (25th percentile) and the third quartile Q3 (75th percentile). The interquartile range is IQR = Q3 − Q1, the width of the middle half of the data. Flag values outside the fences:

  • lower fence = Q1 − 1.5 × IQR
  • upper fence = Q3 + 1.5 × IQR

For delivery times with Q1 = 2 days and Q3 = 5 days, IQR = 3, so the fences are −2.5 and 9.5 days. A 14-day delivery gets flagged. Because quartiles ignore the extremes, the rule works even when outliers are present. It is the rule box plots use to draw individual points.

Z-scores. A z-score measures how many standard deviations a value sits from the mean: z = (x − mean) / SD. A common rule flags |z| > 3. It works well for roughly bell-shaped data, but it has a weakness called masking: big outliers inflate the mean and the SD they are measured against, so they can hide themselves. In a small dataset, a single huge value may not even reach z = 3.

A robust alternative replaces the mean with the median and the SD with the median absolute deviation (MAD). Whatever rule you use, the flag is only a prompt to look, never an automatic delete.

Box plot of delivery times with 1.5 × IQR fences: a 14-day delivery falls outside the upper fence and is flagged-4-20246810121416Q1=2 to Q3=5IQR = 3lower fence −2.5upper fence 9.514 daysflaggeddelivery time (days)

Step 3 of 10Try the calculator

IQR fence calculator

Enter the quartiles of a column to see where the outlier fences fall. The multiplier is usually 1.5; some analysts use 3 to flag only extreme values.

IQR
3
Lower fence
-2.5
Upper fence
9.5

Step 4 of 10Practice · Work it out

Monthly phone bills in a sample have Q1 = $40 and Q3 = $70. Using the 1.5 × IQR rule, what is the upper fence in dollars?

Step 5 of 10Practice · Work it out

Exam scores have a mean of 70 and a standard deviation of 8. What is the z-score of a score of 98?

Step 6 of 10Practice · Choose one

A dataset of 12 values contains one value that is 50 times larger than the rest, yet its z-score is only about 3.2, and in a dataset of 10 values a similar value scored below 3. Why do z-scores struggle here?

Step 7 of 10Compare

What to do with a flagged value

AspectCorrectRemoveCap (winsorize)Keep and use robust methods
WhenYou can find the true value: a typo, unit error or sentinel codeProven error with no way to recover the true value, or a record outside the study scopeReal extremes that would dominate a model or average, when the exact size matters lessGenuine values that matter for the question
Example$95,000,000 corrected to $950,000 from the deed recordA test order placed by the developerIncomes above the 99th percentile set to the 99th percentile valueReport median house price alongside the mean
RiskGuessing the "true" value without evidenceBias, and losing real informationDistorts the top of the distribution; must be disclosedSome methods still sensitive to extremes

Step 8 of 10Practice · What would you do?

What would you do?

An online shop that sells craft supplies has a typical order value of about $60. One order is for $48,000. The IQR rule flags it. What should you do first?

Step 9 of 10Practice · True or false

Outliers should always be removed before analysis so they do not distort the results.

Step 10 of 10Practice · Choose one

A column of house prices is strongly right-skewed with a few genuine luxury sales. You want a single "typical price" figure that is not dominated by them. What is the best choice?