Outlier Detection with Grubbs, Tukey and Z-Scores
After reading this you can decide whether a suspicious value in your data is a genuine outlier, and choose between three standard tests that answer that question in different ways.
What an outlier is, and one quick example
An outlier is a value that sits far from the rest of your data. It might be a typo, a broken sensor, a rare true event, or nothing unusual at all. The word "far" needs a rule, and that is exactly what the three methods here provide.
Take the demo data: 2, 4, 4, 4, 5, 5, 7, 30. Seven of the eight values fall between 2 and 7. The eighth, 30, is far above them. The mean of all eight is 7.625, which is larger than every value except the 30 itself. That is the giveaway: one point is pulling the average past the bulk of the data. Every method on this page will flag 30, but they reach that verdict through different arithmetic and with different assumptions.
The point of a formal test is to replace "that looks too high" with a number you can defend. It also protects you from the opposite error: deleting a value just because it is the largest, when the spread of the data makes it perfectly ordinary.
When to use each method, and when not to
The three methods are not interchangeable. They rest on different pictures of the data.
- Grubbs' test
- Assumes the data are roughly normal (bell-shaped) and tests one value at a time, either the maximum or the minimum. Best for a small, clean sample where you suspect a single contaminated point.
- Tukey's fences
- Uses quartiles, so it makes no assumption about the shape of the distribution. It can flag several points at once and works on skewed data. This is the rule behind the whiskers on a boxplot.
- Z-score rule
- Flags any value more than 3 standard deviations from the mean. Simple, but the mean and standard deviation are themselves distorted by the very outliers you are hunting.
None of these tests tells you an outlier is wrong. A flagged value can be the most important observation in the set. Investigate the cause before you delete anything. Removing points to make a test come out the way you want is a way to fool yourself.
If your data are strongly skewed or multimodal, skip Grubbs and the z-score and rely on Tukey's fences. If you expect more than one bad point, Grubbs is the wrong choice because a second extreme value can mask the first.
The formulas and what they mean
Grubbs' test compares the most extreme value to the mean, measured in standard deviations.
Here \bar{x} is the sample mean, s is the sample standard deviation, and the numerator is the largest absolute distance from the mean. You compare G against a critical value that depends on the sample size n and the significance level (this page uses \alpha = 0.05). If G \gt G_{crit}, the extreme value is an outlier.
In this expression t is the upper \alpha / (2n) critical value of the t-distribution with n-2 degrees of freedom. You do not need to compute this by hand; the point is that the threshold grows slowly with sample size, so a larger sample tolerates a slightly more extreme point before calling it an outlier.
Tukey's rule builds fences from the quartiles.
Q_1 and Q_3 are the first and third quartiles, and the interquartile range \text{IQR} is the middle 50% of the data. Any value outside the fences is flagged. The multiplier 1.5 is a convention that catches genuine extremes without being too jumpy.
The z-score is the plainest of the three.
A value is flagged when |z_i| \gt 3. Under a normal distribution, only about 0.27% of values fall beyond 3 standard deviations, so anything past that line is rare if the data really are normal.
Working through the demo data
Use 2, 4, 4, 4, 5, 5, 7, 30 with n = 8.
- Mean: \bar{x} = (2+4+4+4+5+5+7+30)/8 = 61/8 = 7.625.
- Sample standard deviation: the squared deviations sum to about
541.9, so s = \sqrt{541.9 / 7} \approx 8.799. - Grubbs: the largest distance is |30 - 7.625| = 22.375, so G = 22.375 / 8.799 \approx 2.543. The critical value for
n = 8at \alpha = 0.05 is about2.126. Since 2.543 \gt 2.126,30is an outlier. - Tukey: with these eight sorted values, Q_1 = 4 and Q_3 = 5.5, so \text{IQR} = 1.5. The upper fence is 5.5 + 1.5 \times 1.5 = 7.75. Since 30 \gt 7.75, it is flagged. The lower fence is 4 - 2.25 = 1.75, and the value 2 is inside it.
- Z-score: z = (30 - 7.625) / 8.799 \approx 2.543. That is below the cutoff of 3, so the z-score rule does not flag it.
Two of three methods flag 30. The z-score misses it, and that disagreement is the lesson of the next section.
Why the z-score can miss an obvious outlier
The z-score failed above because the outlier inflated the very standard deviation used to judge it. With 30 in the set, s \approx 8.799. Remove it and the standard deviation of the remaining seven values drops to about 1.512. Against that smaller spread the 30 would score a z of roughly (30 - 4.14)/1.512 \approx 17, far past the cutoff.
This is called masking: an extreme point widens the yardstick so much that it hides its own extremity. With a single suspect value and a small sample, the plain z-score is the weakest of the three. Tukey's fences avoid the problem because quartiles ignore the size of the extremes, and Grubbs is calibrated for exactly this one-point situation.
Reading the results
Expect the three methods to agree on clear cases and disagree at the margins. Treat that disagreement as information, not noise.
| Method | Statistic | Threshold | Flagged? |
|---|---|---|---|
| Grubbs | 2.543 | 2.126 | Yes |
| Tukey upper fence | 30 vs 7.75 | 7.75 | Yes |
| Z-score | 2.543 | 3 | No |
When Tukey flags a point but the z-score does not, suspect masking and trust Tukey. When Grubbs flags a point but Tukey does not, the value is extreme relative to a bell curve but not relative to the raw quartiles; look at whether your data are really normal. When all three agree, you have a strong case.
Common mistakes
The errors below account for most wrong conclusions.
- Deleting outliers by reflex. A flag is a prompt to investigate, not a licence to erase. Record what you remove and why.
- Running Grubbs repeatedly. Grubbs is designed for one outlier. If you delete a point and rerun it, use a version built for multiple outliers rather than looping the single-point test, which loses control of the error rate.
- Using the z-score rule on tiny samples. With
n = 8, no value can even reach |z| = 3 in some configurations, because the largest possible z-score is bounded by (n-1)/\sqrt{n} \approx 2.47. The rule simply cannot fire. - Assuming normality without checking. Grubbs and the z-score both lean on the bell curve. On skewed data such as incomes or wait times, they over-flag the long tail. Use Tukey's fences instead, or transform the data first.
Before running any test, plot the data. A quick look at a dot plot or histogram tells you the shape, and the shape decides which method is trustworthy.
Related tools on this site
Outlier detection is one step in describing a dataset. To see the mean, median, quartiles and standard deviation that feed these tests, use the Descriptive Statistics Calculator. To locate a value's position in the distribution, the Percentile Calculator gives the rank of a value or the value at a rank. If you are checking numbers for signs of fabrication rather than natural extremes, the Benford's Law Checker tests whether leading digits follow the expected pattern.
Frequently asked questions
Why does the z-score say no when Grubbs says yes on the same number?
Both use the mean and standard deviation, but they compare against different thresholds. Grubbs' critical value for n = 8 is 2.126, well below the fixed z-score cutoff of 3. The statistic is 2.543 in both cases, so it clears the Grubbs bar and misses the z-score bar. Grubbs is tuned to the sample size; the plain z-score is not.
Which method should I trust by default?
For general use, start with Tukey's fences. They make no assumption about distribution shape, handle several outliers at once, and match the whiskers of a boxplot. Add Grubbs when you have a small, roughly normal sample and one suspect value.
Can a value be an outlier and still be correct?
Yes. A record-breaking sale, a rare medical result, or a genuine spike are all real data that a test will flag. The test measures distance from the rest, not truth. Keep the value unless you find a specific reason it is wrong.
How much data do I need?
Grubbs needs at least 3 points and works best from about 6 upward. Tukey's fences need enough values to estimate quartiles sensibly, so 5 or more. Below those sizes, no test is reliable; inspect the numbers directly.
Why 1.5 times the IQR and not some other multiplier?
The 1.5 factor is a convention chosen so that, on normal data, only about 0.7% of values fall outside the fences. A multiplier of 3.0 marks "far" outliers instead, catching only the most extreme points. There is no deeper law; pick the level of sensitivity you want.