Skip to content

ADescribe · Guide test 147

Grubbs test

Tests for one extreme observation in an approximately normal univariate sample.

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

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 · Grubbs test

20
1
3.5

How far the planted values sit above the rest.

0.050

Your data

Drag a point away from the rest
Sample · n = 20 · mean 0.24

If H₀ were true

G = 3.42
  1. The reference: how G varies across samples when H₀ is true, Grubbs' G for n = 20 (Bonferroni bound) (Bonferroni bound 2n·P(T > t): exact in the tail).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = < .001).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

G=max⁡i∣xi−xˉ∣s,p=min⁡(1, 2n P(Tn−2>tG))G = \dfrac{\max_i |x_i - \bar x|}{s},\qquad p = \min\Bigl(1,\ 2n\,P\bigl(T_{n-2} > t_G\bigr)\Bigr)

With your numbers

G=3.42,G0.05=2.71,n=20G = 3.42,\qquad G_{0.05} = 2.71,\qquad n = 20
GG
largest distance from the mean in SDs
ss
sample SD, including the suspect
tGt_G
the t value G corresponds to
2n2n
the search over both ends and every value

The verdict

G = 3.42, p < .001

p ≤ α = .050: reject H₀

The p-value multiplies a single t tail by 2n because the test looks at the most extreme of n values. It assumes the rest is normal; with heavy tails, flagged values are often just the tail.

Statistic
3.417
p-value
0.0004
Grubbs test on Sample: n = 20: G = 3.42, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H0.

Grubbs test on Sample: n = 20: G = 3.42, p < .001. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: all observations come from one normal population; H1: one observation is an outlier.

Assumptions

Independent normal observations apart from the possible single outlier; preselect one or two sided form.

Formula

G=max⁡i∣xi−xˉ∣sGcrit=n−1nt∗2n−2+t∗2\begin{gathered}G=\max_i\frac{|x_i-\bar x|}{s}\\[5pt] G_{crit}=\frac{n-1}{\sqrt n}\sqrt{\frac{t_*^2}{n-2+t_*^2}}\end{gathered}

Parameters and notation

For a two sided level α test t*=tn−2,1−α/(2n). x̄,s use all n observations.

Structure of the method

Fit the common normal mean and standard deviation using all observations, identify the largest standardized absolute deviation and compare it with the simultaneous single-outlier threshold. The maximum selection is part of the test, not an ordinary unadjusted z score for a prespecified observation.

Estimated and nuisance parameters

The common location and variance are nuisance estimates. The selected candidate index is a data-dependent output; it is not a fitted contamination probability or proof that a measurement is erroneous.

Settings and design choices

Prespecify upper, lower or two-sided suspicion, significance level and the analysis batch. Repeated tests over batches or after deleting observations need an explicit sequential or multiplicity strategy.

Fitting and adaptation

Refit mean and standard deviation for each new independent batch and use the matching n-dependent critical value. There are no network weights to fine-tune. If multiple outliers are plausible, choose a calibrated multiple-outlier procedure before screening. Investigate instrument records and scientific explanations before deciding whether any value should be corrected or excluded.

Sensitivity and robustness

Several contaminants can mask each other by inflating the fitted variance. Heavy-tailed but valid data may be repeatedly flagged under an inappropriate normal null. Dependence, selective reporting, small n and post hoc transformations change interpretation; report analyses with and without disputed values when scientifically justified.

How to use and calibrate

Reject when G exceeds the critical value; investigate the measurement and scientific cause.

Example application

Flag one unusually extreme laboratory measurement under a normal precision model.

Interpretation and pitfalls

Watch out

Repeatedly removing points and rerunning Grubbs changes error rates. Multiple outliers can mask each other.

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

Single-outlier normal model; repeated unadjusted testing is not a valid multiple-outlier procedure.

Python · invokes R

Not run — Python launcher syntax checked; R backend runtime not verified · needs Python standard library + Rscript; R packages: PMCMRplus

# 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]<-5;print(PMCMRplus::grubbsTest(x))
"""
# 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

Not run — Syntax checked; runtime not verified in the final environment · needs PMCMRplus

set.seed(2026)
x <- rnorm(60)
x[1]<-5;print(PMCMRplus::grubbsTest(x))

Sources

Statistics guide v4 (historical):
Python: Python launcher syntax checked; R backend runtime not verified · R: Syntax checked; runtime not verified in the final 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 147, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT147.