How to Detect Outliers: Grubbs Test, IQR Fences and Modified Z-Score
By Dr. Zubair Khalid, DVM, MS, PhD ·

An outlier is a data point that sits far enough from the rest of a sample that it deserves a second look before you average it, plot it, or fit a model to it. The hard part is that "far enough" is a decision, not a fact. A reading of 12.4 among a handful of values near 10 could be a transcription error, a contaminated sample, or a genuinely rare observation, and the arithmetic alone cannot tell you which.
This article covers three standard approaches: the Grubbs test, the IQR fence rule, and the modified z-score. Each answers a slightly different question, and each fails in a different way. The goal is to help you pick a defensible method, report it honestly, and avoid deleting points that your data actually need.
Quick Answer
- Grubbs test: compute $G = \frac{\max|Y_i - \bar{Y}|}{s}$, then compare it to a critical value from the $t$ distribution. It tests for exactly one outlier and assumes the data are approximately normal [1].
- IQR fences: flag points below $Q_1 - 1.5\,\text{IQR}$ or above $Q_3 + 1.5\,\text{IQR}$ as mild outliers, and points beyond $3\,\text{IQR}$ from the quartiles as extreme [2].
- Modified z-score: compute $M_i = \frac{0.6745\,(x_i - \text{median})}{\text{MAD}}$ and treat $|M| > 3.5$ as a potential outlier [1].
- Never decide from the number alone. Masking and swamping mean one bad point can hide another or drag a good point over the line [1]. Always plot the data.
- Report the rule you used, the threshold, and the count removed. A reader should be able to reproduce your exclusions from the methods section.
Grubbs Test: One Outlier at a Time
The Grubbs test, introduced by Frank Grubbs in 1969, formalizes the intuition that the most extreme point should be judged against the spread of everything else [4]. The test statistic is:
$$G = \frac{\max_i |Y_i - \bar{Y}|}{s}$$
where $\bar{Y}$ is the sample mean, $s$ is the sample standard deviation, and the maximum runs over all observations. You are asking how many standard deviations the worst point sits from the center.
The two-sided critical value is:
$$G_{\text{crit}} = \frac{N-1}{\sqrt{N}} \sqrt{\frac{t^2_{\alpha/(2N),\,N-2}}{N-2+t^2_{\alpha/(2N),\,N-2}}}$$
Here $N$ is the sample size, $t_{\alpha/(2N),\,N-2}$ is the upper tail critical value of the $t$ distribution with $N-2$ degrees of freedom, and $\alpha$ is your chosen significance level. If $G > G_{\text{crit}}$, you reject the null hypothesis that all points come from the same normal population [1].
Two details matter in practice. First, the test assumes approximate normality, so it is not appropriate for heavily skewed counts or bounded proportions. Second, it tests for exactly one outlier. If you suspect several, the standard advice is to use Tietjen-Moore or the generalized ESD procedure instead of running Grubbs repeatedly [1].
There is also a hard ceiling on how large $G$ can get. For any sample, the maximum possible z-score is at most $(N-1)/\sqrt{N}$ [1]. With $N = 8$, that ceiling is 2.475, which means a Grubbs test on eight points can never flag anything more extreme than that no matter how far the point sits.
IQR Fences: The Box Plot Rule
The fence rule comes straight from the box plot. Order your data, find the quartiles, and compute the interquartile range:
$$\text{IQR} = Q_3 - Q_1$$
Then draw two pairs of fences [2]:
- Inner (mild) fences: $Q_1 - 1.5\,\text{IQR}$ and $Q_3 + 1.5\,\text{IQR}$
- Outer (extreme) fences: $Q_1 - 3\,\text{IQR}$ and $Q_3 + 3\,\text{IQR}$
Points outside the inner fences are mild outliers. Points outside the outer fences are extreme outliers [2]. The rule makes no normality assumption, which is its main advantage. It is also the rule most readers already recognize from a box plot, so it needs little explanation in a paper.
The catch is that quartile definitions differ across software. NIST places the lower quartile at the $0.25(N+1)$th ordered point [2]. NumPy's default and Excel's QUARTILE.INC use linear interpolation, which gives different fences on small samples. Neither is wrong, but you should state which one you used, because on $N = 8$ the two conventions can disagree about whether a borderline point is flagged.
Modified Z-Score: Median and MAD
The ordinary z-score uses the mean and standard deviation, both of which are themselves distorted by the outlier you are trying to find. Iglewicz and Hoaglin proposed replacing them with the median and the median absolute deviation (MAD) [1]:
$$M_i = \frac{0.6745\,(x_i - \text{median})}{\text{MAD}}$$
The constant 0.6745 is the 75th percentile of the standard normal distribution, so the modified z-score is scaled to behave like a z-score when the data are normal [1]. The MAD is the median of the absolute deviations from the median [5]. A common convention is to flag any point with $|M| > 3.5$ as a potential outlier [1].
The argument for median-based measures is that the median and MAD have a high breakdown point: a small fraction of extreme values cannot move them much. Leys and colleagues made this case directly, arguing that researchers should use absolute deviation around the median instead of standard deviation around the mean when screening for outliers [3]. The trade-off is lower efficiency when the data really are normal, so the modified z-score is a conservative choice, not a universally better one.
Worked Example
The following data are illustrative and constructed for teaching. Suppose eight replicate measurements from a calibration run:
$$9.8,\ 10.1,\ 10.0,\ 10.3,\ 9.9,\ 10.2,\ 12.4,\ 10.0$$
Grubbs test. The mean is 10.3375 and the sample standard deviation is 0.8484. The largest absolute deviation belongs to 12.4, giving:
$$G = \frac{|12.4 - 10.3375|}{0.8484} = 2.431$$
With $N = 8$, the two-sided critical value at $\alpha = 0.05$ is 2.127, and the one-sided critical value is 2.032. Since 2.431 exceeds both, the point is flagged. Note that the maximum possible z-score for $N = 8$ is 2.475, so this test is operating close to its ceiling.
IQR fences. Using linear interpolation (NumPy default, Excel QUARTILE.INC), $Q_1 = 9.975$, $Q_3 = 10.225$, and $\text{IQR} = 0.25$. The inner fences are 9.60 and 10.60, and the outer upper fence is 10.975. The value 12.4 sits beyond the outer fence, so it is an extreme outlier by this rule.
Using the Weibull convention $0.25(N+1)$, $Q_1 = 9.925$ and $Q_3 = 10.275$, which puts the upper inner fence at 10.80. The conclusion is the same here, but the fence moved by 0.20.
Modified z-score. The median is 10.05 and the MAD is 0.15. For the suspect point:
$$M = \frac{0.6745\,(12.4 - 10.05)}{0.15} = 10.567$$
Every other point has $|M| \le 1.124$. The threshold of 3.5 is crossed by a wide margin.
After removal. Dropping 12.4 leaves seven values with mean 10.0429 and standard deviation 0.1718. Re-running Grubbs on the reduced set gives $G = 1.497$ against a critical value of 2.020 for $N = 7$, so no further point is flagged.
If you want to run these calculations on your own data, the site's Outlier Calculator applies these rules directly.
| Method | Statistic | Threshold | Flags 12.4? |
|---|---|---|---|
| Grubbs (two-sided) | $G = 2.431$ | 2.127 | Yes |
| Grubbs (one-sided) | $G = 2.431$ | 2.032 | Yes |
| IQR inner fence | 10.60 | upper fence | Yes |
| IQR outer fence | 10.975 | upper fence | Yes |
| Modified z-score | $M = 10.567$ | 3.5 | Yes |
Choosing Between the Three
The methods agree here because the outlier is unambiguous. On real data they often disagree, and the choice should follow from your assumptions and your sample size.
| Situation | Reasonable choice |
|---|---|
| Approximately normal data, one suspected point | Grubbs test [1] |
| Skewed data or unknown distribution | IQR fences [2] |
| Small sample, want robustness to extreme values | Modified z-score [1] |
| Several suspected outliers | Tietjen-Moore or generalized ESD [1] |
| Any of the above | Pair with a plot [1] |
Sample size drives a lot of this. The ceiling on $G$ matters when $N$ is tiny: for $N = 3$ the largest possible value is 1.155, so Grubbs has almost no room to flag anything. The IQR rule is stable across distributions but flags a fixed proportion of points in any sample, roughly 0.7 percent under normality, regardless of whether those points are errors.
Common Mistakes
- Running Grubbs repeatedly on the same data. The test is designed for one outlier. Iterating it inflates the false positive rate. Use generalized ESD or Tietjen-Moore when you expect several [1].
- Using the mean and SD to screen for outliers. Both are pulled by the very points you are testing. Switch to median and MAD when robustness matters [3].
- Ignoring masking and swamping. Masking means one outlier hides another; swamping means an outlier drags a legitimate point over the threshold [1]. Plot the data before and after removal.
- Treating a flag as proof of error. A statistical test identifies points that are unlikely under a stated model. It does not tell you the value is wrong.
- Forgetting to report the rule. Reviewers cannot evaluate exclusions if you do not name the test, the threshold, and the software convention for quartiles.
- Mixing quartile conventions. NumPy default and the Weibull convention give different fences on small samples. Pick one and say which.
Limitations
Every method here assumes your data are a random sample from a single population. If the sample contains two real subgroups, say two instrument batches with different means, the between-group difference will look like an outlier. No test can separate that from contamination.
Grubbs assumes approximate normality [1]. On log-normal concentrations, counts, or bounded ratios, the test can flag legitimate values. The IQR rule avoids that assumption but loses power on small samples and is insensitive to the shape of the tails. The modified z-score is robust but conservative, and the 3.5 threshold is a convention, not a probability statement [1].
None of these methods handle multivariate outliers. A point can be unremarkable on every variable individually and still be extreme in the joint space. That requires a different toolkit.
Finally, removal is a modeling decision, not a data-cleaning step. If you remove a point, report the analysis with and without it. If the conclusion changes, that is the finding.
Frequently Asked Questions
What is the difference between the Grubbs test and the IQR rule?
Grubbs is a formal hypothesis test with a critical value derived from the $t$ distribution, and it assumes normality [1]. The IQR rule is a descriptive fence with no distributional assumption [2]. Grubbs gives you a p-value; the fence gives you a label.
Can I use the Grubbs test for more than one outlier?
Not directly. The test is built for exactly one outlier, and repeated application distorts the error rate [1]. For multiple suspected outliers, use Tietjen-Moore or the generalized ESD procedure [1].
Why does the modified z-score use 0.6745?
It is the 75th percentile of the standard normal distribution [1]. Dividing by the MAD and multiplying by this constant rescales the statistic so that it is comparable to a standard z-score when the data are normal.
What threshold should I use for the modified z-score?
The common convention, recommended by Iglewicz and Hoaglin and described in the NIST handbook, is $|M| > 3.5$ [1]. Treat it as a screening rule, not a significance level.
Do I have to remove flagged points?
No. A flag means the point is unusual under your model, not that it is erroneous. Check the raw record, the instrument log, and the sample history first. If the value is plausible, keep it and report the analysis both ways.
References
- NIST/SEMATECH e-Handbook of Statistical Methods: Detection of outliers
- NIST/SEMATECH e-Handbook of Statistical Methods: What are outliers in the data? (box plot fences)
- Leys C, Ley C, Klein O, Bernard P, Licata L. Detecting outliers: do not use standard deviation around the mean, use absolute deviation around the median. Journal of Experimental Social Psychology, 2013
- Grubbs FE. Procedures for detecting outlying observations in samples. Technometrics, 1969
- NIST/SEMATECH e-Handbook of Statistical Methods: Measures of scale (MAD and IQR)