Statistics · Mathematics
One rogue data point can wreck an average, break a machine learning model, or hide a medical breakthrough. Outliers are the most misunderstood values in statistics — sometimes noise, sometimes the most important signal in your dataset. This guide shows you how to find them, what to do with them, and when removing them is actually the wrong call.
Contents
- What is an outlier?
- Why outliers matter — the impact on statistics
- Types of outliers
- How to detect outliers — 4 methods
- Interactive outlier detector
- Visualising outliers with box plots
- How to handle outliers — 5 strategies
- When you should NEVER remove an outlier
- Real-world examples
- Python code
- Knowledge quiz
Section 01
What is an Outlier?
An outlier is a data point that lies far away from the rest of the observations in a dataset. It is a value that is unusually high or low compared to the typical range of the data.
Consider the salaries of five employees: £28k, £31k, £29k, £33k, £420k. That last value — £420k — is an outlier. It could be the CEO’s salary, a data entry error, or a completely different type of employee included by mistake. Each explanation calls for a different response.
📌 No Universal Threshold
There is no single agreed-upon definition of “how far is too far.” Different detection methods use different thresholds. An outlier is always defined relative to the rest of the data and the context of the problem.
Section 02
Why Outliers Matter — The Impact on Statistics
Outliers can have a dramatic or minimal effect depending on which statistical measure you use. The mean is highly sensitive. The median is almost immune. Understanding this asymmetry is one of the most practical skills in applied statistics.
Salary example — the CEO effect
A team of 10 employees. Nine earn between £28,000 and £35,000. One is the CEO earning £500,000.
Including CEO (outlier present)
Median (resistant to outlier)
| Statistic | Sensitivity to Outliers | Why |
|---|---|---|
| Mean | Highly sensitive | Every value is used in the calculation — one extreme value pulls the result |
| Median | Very resistant | Only cares about position — outliers don’t change the middle value |
| Mode | Resistant | Only counts frequency — one extreme value rarely changes the most common |
| Standard Deviation | Highly sensitive | Squared differences amplify the effect of values far from the mean |
| IQR | Very resistant | Based on middle 50% of data — outliers in the tails don’t affect it |
| Correlation (r) | Very sensitive | A single outlier can flip the sign of r from positive to negative |
| Linear Regression | Highly sensitive | The regression line is pulled toward influential outliers (leverage points) |
| Range | Maximally sensitive | Defined entirely by the minimum and maximum — outliers determine it |
💡 Resistance vs Sensitivity
Statistics that use position (median, IQR, quantiles) are called robust or resistant — they are unaffected by outliers. Statistics that use all values in arithmetic calculations (mean, standard deviation, variance) are non-robust and can be severely distorted by even a single outlier.
Section 03
Types of Outliers
Not all outliers are the same. Understanding why a value is an outlier determines what you should do with it.
| Type | Cause | Example | Action |
|---|---|---|---|
| Error outlier | Data entry mistake, sensor malfunction, recording error | Age recorded as 220 instead of 22; a weight sensor reading 0kg due to calibration failure | Investigate and correct or remove |
| Natural outlier | Genuine extreme value — real variation in the population | Usain Bolt’s 100m time in a dataset of sprinters; a billionaire in income data | Keep — it is real and may be meaningful |
| Interesting outlier | Unexpected anomaly that signals something important | An unusually high credit card transaction (fraud detection); a sudden spike in disease cases | Investigate further — it may be the most important data point |
| Structural outlier | Data from a different subgroup accidentally mixed in | Adult heights in a children’s dataset; a commercial property in a residential price dataset | Separate into correct group; do not simply delete |
⚠️ Classify Before You Act
The most important question is: why is this value an outlier? Answering that question determines everything — whether to keep it, remove it, investigate it, or report it. Blindly removing outliers without understanding their cause is one of the most common errors in data analysis.
Section 04
How to Detect Outliers — 4 Methods
Z-Score Method
Calculate how many standard deviations each value is from the mean. Values with |z| > 3 are outliers. Best for normally distributed data.
IQR / Tukey Fences
Uses the interquartile range. Values below Q1 − 1.5×IQR or above Q3 + 1.5×IQR are mild outliers. 3×IQR for extreme outliers. Robust to skewed data.
Upper = Q3 + 1.5×IQR
Modified Z-Score
Uses the median and Median Absolute Deviation (MAD) instead of mean and standard deviation. More robust than regular Z-score. Values with |M| > 3.5 are outliers.
Visual Methods
Box plots show outliers as individual dots beyond the whiskers. Scatter plots reveal spatial outliers. Histograms show isolated bars. Always visualise before calculating.
IQR Method — Worked Example
Dataset: 12, 15, 14, 10, 18, 14, 13, 100, 16, 11
Sort the data
10, 11, 12, 13, 14, 14, 15, 16, 18, 100
Find Q1 and Q3
Q1 (25th percentile) = 11.5 | Q3 (75th percentile) = 15.5
Calculate IQR
IQR = Q3 − Q1 = 15.5 − 11.5 = 4.0
Calculate fences
Lower fence = 11.5 − (1.5 × 4.0) = 5.5
Upper fence = 15.5 + (1.5 × 4.0) = 21.5
Flag outliers
The value 100 is above 21.5 — it is an outlier. All other values fall within [5.5, 21.5].
Section 05
Interactive Outlier Detector
Enter your own dataset (comma-separated numbers) and choose a detection method. The detector will flag outliers instantly and show you the full statistical breakdown.
Section 06
Visualising Outliers with Box Plots
A box plot (also called a box-and-whisker plot) is the standard visual tool for outlier detection. The box shows the IQR (Q1 to Q3). The line inside is the median. The whiskers extend to the Tukey fences. Individual dots beyond the whiskers are outliers.
| Box Plot Element | What it shows | Statistical meaning |
|---|---|---|
| Left edge of box | Q1 | 25th percentile — 25% of data is below this |
| Line inside box | Median (Q2) | 50th percentile — the true middle |
| Right edge of box | Q3 | 75th percentile — 75% of data is below this |
| Box width | IQR = Q3 − Q1 | Middle 50% of the data — resistant to outliers |
| Whiskers | Q1 − 1.5×IQR to Q3 + 1.5×IQR | The “expected” range — Tukey fences |
| Individual dots | Outliers | Any value beyond the whiskers |
Section 07
How to Handle Outliers — 5 Strategies
After detecting an outlier, you have five options. The right one depends on the type of outlier and your analytical goal.
1. Remove it
Delete the value from the dataset. Only appropriate for confirmed error outliers where the value is demonstrably wrong. Never remove without documenting why.
2. Correct it
Fix the error if the true value is known. A weight of 700kg that should be 70kg can be corrected. Always preferable to removal when the correct value is recoverable.
3. Cap it (Winsorising)
Replace the outlier with the nearest fence value (e.g. Q3 + 1.5×IQR). Keeps the data point in the analysis but limits its influence. Common in financial modelling.
4. Transform the data
Apply a log, square root, or Box-Cox transformation to compress the scale. Outliers become less extreme. Useful when skewed data is the underlying issue.
5. Use robust methods
Switch to statistics resistant to outliers: use median instead of mean, IQR instead of standard deviation, robust regression instead of OLS. Keeps all data intact.
✅ Decision Framework
Is it a data error? → Correct or remove it, document your decision.
Is it a real but extreme value? → Keep it, use robust statistics, report it.
Is it suspicious and unexplained? → Investigate before deciding.
Unsure? → Run your analysis both with and without the outlier and report both results.
Section 08
When You Should NEVER Remove an Outlier
The phrase “never ignore them” in the title of this article is deliberate. Outliers are sometimes the most important data points. Here is when removing them would be a serious mistake:
Fraud Detection
An outlier transaction — an unusually large purchase in an unusual location — is the fraud. Removing outliers from a fraud detection model trains it to ignore the very signals it should catch.
Never removeDisease Outbreaks
A sudden spike in illness cases in one region is an outlier in epidemiological data. That outlier is the outbreak. Smoothing it away could delay a public health response.
Never removeScientific Discovery
The discovery of penicillin began with an outlier — a petri dish where bacteria unexpectedly failed to grow near a mould. Fleming investigated rather than discarded.
Always investigateQuality Control
A machine part that is far outside tolerance is an outlier in production data. That outlier signals equipment failure. Removing it from reports hides a critical manufacturing defect.
Never removeClimate Science
Unusual temperature or CO₂ readings that deviate from historical patterns are outliers. These anomalies are often the most scientifically significant observations in the dataset.
Always investigateMarket Crashes
Financial crises appear as extreme outliers in stock return data. Removing them from risk models (as many banks did pre-2008) leads to catastrophically underestimated risk.
Never remove🔑 The Golden Rule
Never remove an outlier simply because it makes your analysis messier, your p-value higher, or your graph look cleaner. Outliers must be understood, not just eliminated. If you remove an outlier, document it explicitly, explain why, and consider reporting your analysis both ways.
Section 09
Real-World Examples
| Field | The Outlier | Type | Correct Action |
|---|---|---|---|
| Income data | Billionaires in a national income survey | Natural | Use median not mean; report separately; use log scale |
| Medical trials | Patient with extreme drug response | Interesting | Investigate — may indicate a genetic subgroup; never remove |
| Sports statistics | Usain Bolt’s 9.58s 100m world record | Natural | Keep — it is a genuine data point; report as exceptional |
| Customer data | Customer age entered as 999 | Error | Remove or set to null; flag for data quality review |
| Manufacturing | Component 50× outside tolerance | Interesting | Halt production; investigate equipment; never delete from log |
| House prices | Luxury penthouse in a suburb dataset | Structural | Analyse luxury and non-luxury properties separately |
| Network security | Server traffic spike at 3am | Interesting | Investigate immediately — likely a breach or attack |
Section 10
Python Code
IQR Method
import numpy as np data = np.array([12, 15, 14, 10, 18, 14, 13, 100, 16, 11, 9, 17]) Q1 = np.percentile(data, 25) Q3 = np.percentile(data, 75) IQR = Q3 - Q1 lower_fence = Q1 - 1.5 * IQR upper_fence = Q3 + 1.5 * IQR outliers = data[(data < lower_fence) | (data > upper_fence)] clean = data[(data >= lower_fence) & (data <= upper_fence)] print(f"Q1={Q1}, Q3={Q3}, IQR={IQR}") print(f"Fences: [{lower_fence:.1f}, {upper_fence:.1f}]") print(f"Outliers: {outliers}") # → [100] print(f"Clean data: {clean}")
Z-Score Method
from scipy import stats import numpy as np data = np.array([12, 15, 14, 10, 18, 14, 13, 100, 16, 11]) z_scores = np.abs(stats.zscore(data)) threshold = 3.0 outliers = data[z_scores > threshold] print(f"Z-scores: {z_scores.round(2)}") print(f"Outliers (|z| > {threshold}): {outliers}") # → [100]
Modified Z-Score (most robust)
import numpy as np def modified_zscore(data): median = np.median(data) mad = np.median(np.abs(data - median)) # Median Absolute Deviation return 0.6745 * (data - median) / mad data = np.array([12, 15, 14, 10, 18, 14, 13, 100, 16, 11]) m_scores = np.abs(modified_zscore(data)) outliers = data[m_scores > 3.5] print(f"Outliers: {outliers}") # → [100]
Winsorising (capping outliers)
from scipy.stats import mstats import numpy as np data = np.array([12, 15, 14, 10, 18, 14, 13, 100, 16, 11]) # Winsorise at 5th and 95th percentiles winsorised = mstats.winsorize(data, limits=[0.05, 0.05]) print(f"Original: {data}") print(f"Winsorised: {np.array(winsorised)}") # 100 is replaced with the 95th percentile value # Log transformation for right-skewed data log_data = np.log1p(data) # log(1+x) handles zeros safely print(f"Log: {log_data.round(2)}") # 100 → 4.62, rest compressed into smaller range
Box plot visualisation with matplotlib
import matplotlib.pyplot as plt import numpy as np data = [12, 15, 14, 10, 18, 14, 13, 100, 16, 11, 9, 17] fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 4)) # Box plot bp = ax1.boxplot(data, vert=False, patch_artist=True, flierprops=dict(marker='o', color='red', markersize=8)) bp['boxes'][0].set_facecolor('#99f6e4') ax1.set_title('Box Plot — red dots are outliers') ax1.set_xlabel('Value') # Dot plot ax2.scatter(data, [1]*len(data), alpha=0.7, s=80, c=['#e11d48' if x > 21 else '#0d9488' for x in data]) ax2.set_title('Dot Plot — red = outlier') ax2.set_yticks([]) plt.tight_layout() plt.show()
Section 11
Knowledge Quiz
Six questions to test your understanding of outliers in statistics.

