Skip to main content

Grubbs' Test for Outliers

NIST/SEMATECH Section 1.3.5.17.1 Grubbs' Test for Outliers

What It Is

Grubbs' test (also known as the maximum normed residual test) detects a single outlier in a univariate dataset assumed to come from a normally distributed population. It tests whether the most extreme value (maximum or minimum) is statistically aberrant.

When to Use It

Use Grubbs' test when you suspect that a single data point in a dataset may be an outlier and you want a formal statistical test rather than relying solely on visual inspection. It is commonly used in laboratory settings, quality control, and measurement science to identify and potentially remove anomalous readings. The test is designed for one outlier at a time; for multiple outliers, apply iteratively or use other methods.

How to Interpret

If the computed G statistic exceeds the critical value, reject the null hypothesis and conclude that the most extreme value is a statistical outlier. The test is designed for a single outlier: if you suspect multiple outliers, apply the test iteratively by removing one outlier at a time and retesting. However, masking effects can occur when multiple outliers are present simultaneously, potentially causing the test to miss them. Always visualize the data with a box plot or histogram to supplement the formal test. If an outlier is confirmed, investigate its cause before deciding whether to remove it.

Assumptions and Limitations

Grubbs' test assumes the data (excluding the suspected outlier) come from a normal distribution. The test is designed for independent observations and a single outlier. It should not be applied to very small samples (typically n >= 7 is recommended) because the test has low power in small samples.

Reference: NIST/SEMATECH e-Handbook, Section 1.3.5.17.1

Formulas

Grubbs' G Statistic

G=maxi=1,,nxixˉsG = \frac{\max_{i=1,\ldots,n} |x_i - \bar{x}|}{s}

The ratio of the largest absolute deviation from the sample mean to the sample standard deviation. A large G indicates a potential outlier.

Critical Value

Gcrit=(n1)ntα/(2n),n22n2+tα/(2n),n22G_{\text{crit}} = \frac{(n-1)}{\sqrt{n}}\sqrt{\frac{t_{\alpha/(2n),\,n-2}^2}{n - 2 + t_{\alpha/(2n),\,n-2}^2}}

The critical value for a two-sided Grubbs' test at significance level alpha, derived from the t-distribution with n-2 degrees of freedom.

Python Example

import numpy as np
from scipy import stats
# Sample data with a potential outlier
data = np.array([12.1, 11.5, 13.2, 12.8, 11.9, 12.4, 25.3, 12.6,
11.7, 12.3, 13.5, 12.0])
# Grubbs' test (manual computation -- no direct scipy function)
n = len(data)
mean = np.mean(data)
std = np.std(data, ddof=1)
# G statistic
G = np.max(np.abs(data - mean)) / std
# Critical value (two-sided, alpha = 0.05)
alpha = 0.05
t_crit = stats.t.ppf(1 - alpha / (2 * n), n - 2)
G_crit = ((n - 1) / np.sqrt(n)) * np.sqrt(t_crit**2 / (n - 2 + t_crit**2))
outlier_idx = np.argmax(np.abs(data - mean))
print(f"Suspected outlier: {data[outlier_idx]} (index {outlier_idx})")
print(f"G statistic: {G:.4f}")
print(f"G critical: {G_crit:.4f}")
print(f"Is outlier (alpha=0.05): {G > G_crit}")