Outliers can often distort or skew the analysis of experimental data. Detecting and appropriately dealing with outliers is crucial for robust statistical analyses. Grubbs’ test, also known as the maximum normed residual test or extreme studentized deviate test, is a formal test to detect one outlier at a time in a dataset.
In this in-depth guide, we’ll explore the intricacies of Grubbs’ Test, guide you on data preparation, demonstrate how to carry out the test in R, and provide insights on interpreting the results.
Understanding Grubbs’ Test
Grubbs’ test detects one outlier at a time. This test is based on the assumption that the data follows a Gaussian or normal distribution. The null hypothesis for the test is that there are no outliers in the data set, and the test is designed to test the hypothesis that the minimum or the maximum value is an outlier.
The Grubbs’ statistic is calculated as:

Where:
- Xi is the data point being tested.
- Xˉ is the mean of the dataset.
- s is the standard deviation of the dataset.
If G exceeds a critical value, then Xi can be considered an outlier.
Preparing Your Data
Ensure your data is in a vector format. For instance, consider a dataset that records measurements of a certain chemical concentration:
# Sample data
concentration <- c(5.1, 5.3, 4.9, 5.0, 5.2, 5.5, 12.3, 5.2)
Before conducting Grubbs’ test, it’s good practice to visually inspect the data, often using a boxplot or a histogram, to see if any potential outliers are evident.
Performing Grubbs’ Test in R
While R’s base package doesn’t include a function for Grubbs’ test, the outliers
package offers a convenient function called grubbs.test()
:
# Installing and loading the required package
install.packages("outliers")
library(outliers)
# Conducting Grubbs' test
result <- grubbs.test(concentration, type = 11)
print(result)
The “type” argument specifies the test type. For instance, type = 11
tests the two-sided alternative hypothesis that the minimum or maximum value is an outlier.
Interpreting the Results
An example output might be:
Grubbs test for one outlier
data: concentration
G = 3.7812, U = 0.8572, p-value = 0.0029
alternative hypothesis: highest value 12.3 is an outlier
Let’s interpret this:
- G: This is the Grubbs’ test statistic for the dataset. A larger value indicates a stronger deviation from the mean.
- U: This is the computed statistic divided by the critical value. It should be less than 1 to reject the null hypothesis at the specified significance level.
- p-value: This informs us about the significance of the results. A small p-value (typically ≤ 0.05) suggests strong evidence against the null hypothesis, indicating the presence of an outlier.
From the results, given the p-value is 0.0029 (less than 0.05), we would conclude that the value 12.3 is an outlier.
Caveats and Considerations
- Sequential Testing: Since Grubbs’ test detects one outlier at a time, it’s possible to apply the test sequentially. After detecting and removing an outlier, you can re-run the test on the modified dataset to check for another outlier. However, each time you remove an outlier and re-test, it increases the likelihood of a type I error.
- Normality Assumption: Grubbs’ test assumes that the data is normally distributed. Before running the test, consider conducting a normality test, such as the Shapiro-Wilk test or Kolmogorov-Smirnov test.
- Dataset Size: Grubbs’ test is most suitable for datasets with more than 6 and fewer than 30 observations. For larger datasets, other outlier detection techniques might be more appropriate.
Conclusion
Grubbs’ test is a handy tool for formally detecting outliers in a dataset, especially when dealing with relatively small datasets expected to be normally distributed. By leveraging the outliers
package in R, you can efficiently perform this test and determine whether any data points need reconsideration or removal. As with any statistical test, understanding its assumptions and the context of your data is paramount. Outliers can provide valuable insights into the phenomena you’re studying, so always consider the implications of retaining or removing them from your analysis.