ADescribe · Guide test 147
Grubbs test
Tests for one extreme observation in an approximately normal univariate sample.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Outliers (univariate) — Which values of a numeric variable are unusually far from the rest?
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
How far the planted values sit above the rest.
Your data
Drag a point away from the restIf H₀ were true
- 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).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = < .001).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- largest distance from the mean in SDs
- sample SD, including the suspect
- the t value G corresponds to
- 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 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
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.
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()
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
- PMCMRplus — PMCMRplus · grubbsTestAuthor documentation/source reviewed: PMCMRplus 1.9.12.search.r-project.org
- grubbsTestsearch.r-project.org
- 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.