Z-scores for outliers: what three standard deviations mean
A Z-score says how many standard deviations a value sits from the mean. Anything beyond three is rare enough to inspect.
The arithmetic
Z = (x − mean) / standard deviation. With a mean of 1,000,000 and a standard deviation of 400,000, a value of 2,200,000 has Z = 3.0, three deviations above the mean.
Dividing by n rather than n−1 changes the result slightly. With hundreds of rows the difference is small; with tens, prefer the sample formula.
WITH s AS (
SELECT revenue FROM orders WHERE revenue IS NOT NULL
), m AS (
SELECT AVG(revenue) AS mu, SQRT(AVG(revenue*revenue) - AVG(revenue)*AVG(revenue)) AS sd FROM s
)
SELECT ROUND(mu,0) AS mean, ROUND(sd,0) AS sd,
ROUND(mu + 3*sd, 0) AS upper_3sigma
FROM m;
Why three, and where it fails
Under a normal distribution about 0.27% of values exceed |Z| = 3, which makes it a convenient boundary. For data that is not normal, that interpretation does not hold.
In right-skewed revenue the standard deviation grows with the large values, so even a big order may stay under Z = 3. In very large datasets tens of values can exceed three sigma, and only the largest few are worth reviewing.
| |Z| | Share under normality | Practical reading |
|---|---|---|
| 1.5 | about 13.4% | far too many to flag |
| 2 | about 4.6% | worth a look |
| 3 | about 0.27% | outlier candidate |
| 4 | about 0.006% | highly unusual |
When the deviation is zero
If every value is identical the standard deviation is zero and the division is undefined. SQLite returns NULL rather than an error, so the column silently empties. QueryDeck skips the Z-score in that case and shows IQR only.
Single-value columns and mostly-NULL columns behave the same way. Check the value count and the deviation in the profile panel first.
Using both rules together
The two rules see different things. IQR is rank-based and tolerant of distribution shape; a Z-score measures distance from the mean directly. A row flagged by both is a strong candidate, and a row flagged by one describes the shape of the data.
QueryDeck computes both for the result table and reports per-column counts in the profile panel. Neither rule deletes anything.
Questions
Can a negative Z-score be an outlier?
It means below the mean. Judge by absolute value, so −3.2 counts like 3.2.
Is Z-score unusable for non-normal data?
It is usable but weaker to interpret. Log-transform the values or make IQR the primary rule.
Sources
Every query in this guide runs against the built-in sample data.
Open the lab