grubbsTest
Performs Grubbs' test for detecting a single outlier in a univariate dataset.
Grubbs' test (also called the extreme studentized deviate test) checks whether the observation farthest from the sample mean is a statistically significant outlier, assuming the data are normally distributed. The test statistic G is the ratio of the maximum absolute deviation from the mean to the sample standard deviation. The p-value is computed by converting G to a t-statistic and applying a Bonferroni correction for testing all N observations.
If all values are identical (zero standard deviation), returns G = 0 and p-value = 1. If any value is non-finite (NaN or Infinity), returns NaN for both statistic and p-value.
Example:
val latencies = doubleArrayOf(12.0, 14.0, 11.0, 13.0, 15.0, 98.0, 12.0)
val result = grubbsTest(latencies)
result.statistic // G statistic
result.pValue // p-value (Bonferroni-corrected)
result.additionalInfo["outlierIndex"] // index of the suspected outlier
result.additionalInfo["outlierValue"] // value of the suspected outlier
result.isSignificant() // true if the outlier is significant at 5%Return
a TestResult containing the G statistic, Bonferroni-corrected p-value, degrees of freedom (n − 2), and additional info with "outlierIndex" and "outlierValue".
Parameters
the observed values. Must have at least 3 elements.
the direction of the alternative hypothesis. Alternative.TWO_SIDED tests the value with the largest absolute deviation; Alternative.GREATER tests the maximum; Alternative.LESS tests the minimum. Defaults to Alternative.TWO_SIDED.