labqc.outliers¶
Grubbs and Cochran outlier tests (ISO 5725-2). When to use them: method validation and interlaboratory data, handbook chapter 7.2 (methods).
Outlier tests for laboratory data: Grubbs (one or two outliers) and Cochran (variances).
Used as in ISO 5725-2: a test statistic is compared with its critical values at the 5 % and 1 % significance levels.
ok not significant at 5 %
straggler significant at 5 % but not at 1 %: keep the value, but look for a cause
outlier significant at 1 %: investigate; exclude only with a technical reason
Grubbs, one value G = max |x_i - mean| / s. Critical values from Student's t, G_crit = ((n - 1) / sqrt(n)) * sqrt(t^2 / (n - 2 + t^2)), t = t(1 - alpha / (2n), n - 2). Grubbs, two values G = S_pair / S_0, the sum of squared deviations without the two largest (or two smallest) values, divided by that of all n values; small values are significant. The test takes the smaller ratio of the two pairs, so like the single test it is two-sided. No closed form: critical values are estimated by simulation (normal samples, fixed seed) and agree with published tables to about +/- 0.001. Cochran C = s_max^2 / sum(s_i^2) over p groups of n replicates each, testing the largest variance. Critical values from the F distribution, C_crit = 1 / (1 + (p - 1) / F(1 - alpha / p; n - 1, (p - 1)(n - 1))).
A test assumes the data are otherwise normal; one test at a time, and after removing a confirmed outlier the test may be repeated on the rest.
OutlierTest
dataclass
¶
Result of one test.
test: "grubbs", "grubbs_two" or "cochran". statistic: G or C. critical_95, critical_99: the critical values (for grubbs_two, the statistic is significant when below them). label: "ok", "straggler" or "outlier". suspect: the value(s) tested (for Cochran, the largest variance) and index: their position(s) in the input (for Cochran, the group). side: "high" or "low" for Grubbs, None for Cochran. n: values (Grubbs) or groups.
Source code in src/labqc/outliers.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | |
grubbs_critical ¶
grubbs_critical(n: int, alpha: float) -> float
Critical value of the single-outlier Grubbs test (two-sided) for n values.
Source code in src/labqc/outliers.py
78 79 80 81 82 83 | |
grubbs ¶
grubbs(values: Sequence[float]) -> OutlierTest
Grubbs test for one outlier: the value furthest from the mean (ISO 5725-2, 7.3.4).
Source code in src/labqc/outliers.py
86 87 88 89 90 91 92 93 94 95 96 97 98 | |
grubbs_two_critical
cached
¶
grubbs_two_critical(n: int) -> tuple[float, float]
(5 %, 1 %) lower critical values of the two-outlier Grubbs statistic, by simulation.
The 5 % and 1 % quantiles of min(S_high / S_0, S_low / S_0) for n normal values (the smaller ratio of the two largest and the two smallest values), from 200 000 simulated samples with a fixed seed, so the values are repeatable.
Source code in src/labqc/outliers.py
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
grubbs_two ¶
grubbs_two(values: Sequence[float]) -> OutlierTest
Grubbs test for two outliers: the two largest or the two smallest values, whichever pair gives the smaller (more significant) ratio (ISO 5725-2, 7.3.4).
Source code in src/labqc/outliers.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
cochran_critical ¶
cochran_critical(p: int, n: int, alpha: float) -> float
Critical value of Cochran's C for p groups of n replicates each.
Source code in src/labqc/outliers.py
146 147 148 149 150 151 | |
cochran ¶
cochran(groups: Sequence[Sequence[float]]) -> OutlierTest
Cochran's test for the largest variance among p groups (ISO 5725-2, 7.3.2).
Each group is the replicate results of one laboratory, day or level; all groups need the same number of replicates n (at least 2).
Source code in src/labqc/outliers.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | |