Skip to content

ADescribe · Guide test 149

Tietjen–Moore test

Tests for a prespecified number of outliers in an approximately normal sample.

Runs in CodeSplashPython (calls R) example not runR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

Do it in CodeSplash Run this test on your own data, in Python or R.

Bench

Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.

Bench · Tietjen–Moore test

25
2
3.5

How far the planted values sit above the rest.

2
0.050

Your data

Drag a point away from the rest
Sample · n = 25 · mean 0.14

If H₀ were true

E_k = 0.42
  1. The reference: how E_k varies across samples when H₀ is true, E_k for n = 25, k = 2 (Monte Carlo null: 1,999 samples simulated under H₀ (seed 20261107)).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .009).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

Ek=∑kept(xi−xˉkept)2∑i(xi−xˉ)2E_k = \dfrac{\sum_{\text{kept}} (x_i - \bar x_{\text{kept}})^2}{\sum_i (x_i - \bar x)^2}

With your numbers

E2=0.42,n=25E_{2} = 0.42,\qquad n = 25
EkE_k
share of the total sum of squares left after removing the k most distant values
kk
number of suspected outliers, fixed in advance

The verdict

E_k = 0.42, p = .009

p ≤ α = .050: reject H₀

Small E_k means the removed values carried much of the spread. k must be chosen before looking; testing several k is a different procedure (generalized ESD).

Statistic
0.420
p-value
0.0095
Tietjen–Moore test on Sample: n = 25: E_k = 0.42, p = .009. The p-value is below α = .050, so the data are hard to reconcile with H0.

Tietjen–Moore test on Sample: n = 25: E_k = 0.42, p = .009. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: no outliers; H1: exactly k specified extreme candidates are outliers.

Assumptions

Independent normal observations except potential contaminants; k and one/two sided form fixed in advance.

Formula

Ek=∑i∈R(xi−xˉR)2∑i=1n(xi−xˉ)2E_k=\frac{\sum_{i\in R}(x_i-\bar x_R)^2}{\sum_{i=1}^{n}(x_i-\bar x)^2}

Parameters and notation

R retains n−k values after removing the specified extreme candidates; two sided implementations rank absolute deviations to choose candidates.

Structure of the method

Identify the prespecified number k of extreme candidates using the declared one- or two-sided ranking rule. Compare residual variation among retained observations with total residual variation; small ratios indicate unusually large reduction after removal.

Estimated and nuisance parameters

Estimate a full-sample mean and a retained-sample mean. Candidate identities are selected by the rule, but k is a prespecified design choice rather than a parameter estimated without penalty.

Settings and design choices

Fix k, sidedness, significance level and simulation budget. The two-sided absolute-deviation ranking and the one-sided ordered-tail rule are different algorithms and must not share unverified critical values.

Fitting and adaptation

Simulate normal samples of the same size and rerun candidate selection, both mean calculations and the variance ratio for every replicate. Refit for each new batch; this is selection-aware null calibration, not fine-tuning. If k is unknown, use a method designed for an upper bound rather than trying many k values and reporting one unadjusted result.

Sensitivity and robustness

Incorrect k can reduce power or cause misinterpretation, and multiple outliers may mask one another. A legitimate heavy-tailed distribution can trigger rejection. Degenerate retained variance, duplicated values, dependence and selection of k after viewing the data all require explicit investigation before any exclusion decision.

How to use and calibrate

Small Ek rejects; critical values are usually obtained by simulation of the entire selection rule under a normal null.

Example application

Check a prespecified suspicion that two measurements are contaminated.

Interpretation and pitfalls

Watch out

The method needs k in advance; it does not estimate an arbitrary number of outliers without further calibration.

What changed in edition 2

  • New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.

Python and R

Two-sided Tietjen–Moore with the number of suspected outliers k=2 specified in advance. Small residual/total sums-of-squares ratio is evidence against the null.

Python · invokes R

Not run — Executed end to end through Rscript · needs Python standard library + Rscript; R packages: base R

# Python launcher for the complete R implementation below.
# Requires Rscript on PATH and the listed R packages.
import shutil
import subprocess
rscript = shutil.which("Rscript")
if rscript is None:
    raise RuntimeError("Install R and make Rscript available on PATH.")
r_code = r"""
set.seed(2026)
x <- rnorm(60)
x[1:2]<-c(5,6);k<-2
TM<-function(x,k) {keep<-order(abs(x-mean(x)))[seq_len(length(x)-k)];sum((x[keep]-mean(x[keep]))^2)/sum((x-mean(x))^2)}
T<-TM(x,k);B<-999;null<-replicate(B,TM(rnorm(length(x)),k))
print(c(statistic=T,p=(1+sum(null<=T))/(B+1)))
"""
# No shell interpolation. A failed R execution raises an error in Python.
result = subprocess.run([rscript, "--vanilla", "-"], input=r_code,
                        text=True, capture_output=True)
print(result.stdout)
if result.stderr:
    print(result.stderr)
result.check_returncode()
R

Validated — Executed successfully in the validation environment · needs Base/standard library

set.seed(2026)
x <- rnorm(60)
x[1:2]<-c(5,6);k<-2
TM<-function(x,k) {keep<-order(abs(x-mean(x)))[seq_len(length(x)-k)];sum((x[keep]-mean(x[keep]))^2)/sum((x-mean(x))^2)}
T<-TM(x,k);B<-999;null<-replicate(B,TM(rnorm(length(x)),k))
print(c(statistic=T,p=(1+sum(null<=T))/(B+1)))
Output
statistic         p 
0.4546189 0.0010000

Sources

Statistics guide v4 (historical):
Python: Executed end to end through Rscript · R: Executed successfully in the validation environment
Reference's record:
Edition 2 review: Python: skip · R: not executed (Rscript unavailable); why not run: Python: Python-to-R bridge; Rscript is unavailable. R code was not executed. Python: Not run in the reference's review: Python-to-R bridge; Rscript is unavailable. R code was not executed. R: Reviewed but not run: R wasn't available to the reference's authors.

From the CodeSplash statistics guide (v4), entry 149, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT149.