Ceiling of the Classical z-Score

Version 7 | Created: 2026-08-18 | Updated: 2026-11-07 13:46 UTC
- 1. Scope
- 2. Bound
- 3. Consequence
- References
- Appendix A. Terminology
- Appendix B. Reference Implementation
- Appendix C. Worked Example
A note on the largest absolute z-score a sample of a given size can produce, the derivation of that bound, and what it costs a rule that flags observations by comparing a z-score against a fixed cut-off.
The most common way to call an observation extreme is to divide its deviation from the mean by the standard deviation and compare the result against a cut-off. Both the centre and the scale in that ratio come from the same sample the observation belongs to, so the observation under test sits inside its own denominator.
That self-reference has a consequence that is easy to miss. The ratio has a ceiling, and the ceiling is fixed by the sample size alone. For a small enough sample it falls below the cut-off, and the rule then flags nothing, whatever the data are.
This document gives that ceiling, derives it, and shows what it costs a rule at a fixed cut-off. It is about the arithmetic of the score, not about what should be done with an outlier once one is found.
Write
The bound is due to Shiffler (1988). It is arithmetic rather than a property of any sample, and
it holds for every set of
The derivation needs two identities. Deviations from the mean sum to zero, and the sample standard deviation is defined from their squares.
Fix one observation and write
Rearranging gives
Only the second identity involves
The Cauchy-Schwarz step is an equality when the
The ceiling is therefore attained rather than approached, which is what makes it worth stating. A bound no sample comes near would say little about the rules built on the score.
A rule that flags an observation when
Table 1. The ceiling at several sample sizes
| Sample size n | Largest attainable absolute z | A rule at 3.5 |
|---|---|---|
| 10 | 2.8460 | Can never fire |
| 14 | 3.4744 | Can never fire |
| 15 | 3.6148 | Can fire, barely |
| 20 | 4.2485 | Can fire |
| 54 | 7.2124 | Can fire |
The smallest sample a rule can fire in follows from its cut-off. A cut-off of 3 needs at least 11 observations, and a cut-off of 3.5 needs at least 15. Test fourteen observations at 3.5 and the answer is settled before the data are read.
The danger is that nothing says so. No part of the output distinguishes a sample carrying no extreme observation from a sample too small for the rule to report one.
The constant
The two differ by enough to matter near a cut-off. A score computed with numpy.std at its
default ddof=0 is measured against
[1] Shiffler, R. E. (1988). Maximum Z Scores and Outliers. The American Statistician, 42(1), 79–80.
[2] Barnett, V., & Lewis, T. (1994). Outliers in Statistical Data, 3rd edition. Wiley, Chichester. https://www.wiley.com. ISBN 978-0-471-93094-5.
- ceiling — The largest value a statistic can take over all samples of a given size, as opposed to a critical value, which is a cut-off chosen to control an error rate.
- degrees of freedom correction (ddof) — The amount subtracted from the sample size to form the divisor of the sum of squared deviations. A correction of 1 gives the sample standard deviation and a correction of 0 gives the population form.
- outlier — An observation that is inconsistent with the distribution the rest of the sample follows, in the sense used by Barnett and Lewis (1994). The label concerns consistency with a model and does not by itself establish that the observation is wrong.
- z-score — The deviation of an observation from the sample mean, divided by the sample standard deviation.
The block below is z_score_ceiling.py, in the folder of this document. It is that file as
written, without the module docstring and the if __name__ == '__main__': guard.
The file holds the score and its ceiling and nothing else. Tabulating them and drawing them are left to whatever calls it.
# Math/ZScore/z_score_ceiling.py
__author__ = 'yRocket'
__version__ = "0.0.0.2026.8.18" # Semantic Versioning: Major.Minor.Patch.Date(YYYY.M.D)
# Everything this module offers. The names beginning with an underscore are internal.
__all__ = [
'DEFAULT_DDOF',
'classical_z_scores',
'max_attainable_z',
]
import numpy as np
# The divisor of the sum of squares is n - ddof. The sample standard deviation uses ddof = 1, and
# the ceiling below is written for it; ddof = 0 is the population form and has its own ceiling.
DEFAULT_DDOF = 1
def _as_ddof(ddof: int = DEFAULT_DDOF) -> int:
"""Return the divisor correction, refusing a value the ceiling is not defined for."""
if ddof not in (0, 1):
raise ValueError(f"ddof must be 0 or 1, got {ddof}.")
return int(ddof)
def _as_sample(data: np.ndarray = None) -> np.ndarray:
"""Return the sample as a 1-D float array, refusing input a z-score cannot be taken in."""
values = np.asarray(data, dtype=float)
if values.ndim != 1:
raise ValueError(f"data must be 1-D, got shape {values.shape}.")
if values.size < 2:
raise ValueError(f"a z-score needs at least 2 observations to have a scale, got {values.size}.")
if not np.all(np.isfinite(values)):
raise ValueError(f"data carries {int((~np.isfinite(values)).sum())} non-finite values; "
f"remove or impute them before scoring.")
return values
def classical_z_scores(data: np.ndarray = None, ddof: int = DEFAULT_DDOF) -> np.ndarray:
"""Deviation of every observation from the mean, divided by the standard deviation.
Args:
data: the sample, shape (n,).
ddof: the divisor correction, 1 for the sample standard deviation and 0 for the
population form.
Returns:
The classical z-scores, shape (n,).
"""
values = _as_sample(data=data)
correction = _as_ddof(ddof=ddof)
scale = float(values.std(ddof=correction))
if scale == 0.0:
# Every observation equals the mean, so no observation is any distance from it at all.
# Returning zeros would report a clean sample where the score is simply not defined.
raise ValueError(f"the standard deviation is 0 because all {values.size} observations are "
f"{float(values[0])}; the classical score is undefined.")
return (values - values.mean()) / scale
def max_attainable_z(size: int = None, ddof: int = DEFAULT_DDOF) -> float:
"""Largest absolute z-score a sample of the given size can produce, whatever its values.
The bound is arithmetic rather than a property of any data, and it is attained: one
observation set apart from size - 1 tied ones reaches it exactly.
Args:
size: the number of observations.
ddof: the divisor correction, as in classical_z_scores.
Returns:
The ceiling on the absolute z-score.
"""
correction = _as_ddof(ddof=ddof)
if not isinstance(size, (int, np.integer)):
raise ValueError(f"size must be an integer, got {type(size).__name__}.")
if size < 2:
raise ValueError(f"size must be at least 2, got {size}.")
if correction == 1:
return float((size - 1) / np.sqrt(size))
return float(np.sqrt(size - 1))Every number in this appendix is produced by z_score_worked_example.py, invoked as
python3 z_score_worked_example.py --threshold 3.5. The script reads the sample from
EDA/Outlier/data/1d_esc_current.csv and writes the points behind the figure beside the figure
as CSV.
The sample is fifteen current measurements. Fourteen of them sit near 0.02 and one is 0.6532, which is the shape section 2.3 describes: one observation set apart from a tight group. It therefore sits close to the configuration that attains the ceiling, which here is nothing distant: it stands a few thousandths above the largest score in the sample.
Table 2. The sample against its ceiling, and the ceiling one observation lower
| Quantity | Value |
|---|---|
| Observations | 15 |
| Mean | 0.062913 |
| Standard deviation | 0.163469 |
| Largest absolute z | 3.611012 |
| Ceiling at n = 15 | 3.614784 |
| Share of the ceiling reached | 99.90% |
| Ceiling at n = 14 | 3.474396 |
A rule at 3.5 flags that largest score, but it clears the cut-off by 0.111 while sitting only 0.004 below the ceiling. The verdict rests on the sample size almost as much as on the measurement.
Removing one observation makes that plain. At fourteen the ceiling is 3.474396, below the cut-off, so the same measurement in a sample one smaller could not be flagged at 3.5 at all.
Fig 1. The ceiling against sample size, and the scores this sample reaches under it
Panel (a) draws

