mcmaster-epg 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. mcmaster_epg-1.0.1/.gitignore +6 -0
  2. mcmaster_epg-1.0.1/CHANGELOG.md +23 -0
  3. mcmaster_epg-1.0.1/CITATION.cff +50 -0
  4. mcmaster_epg-1.0.1/LICENSE +21 -0
  5. mcmaster_epg-1.0.1/PKG-INFO +443 -0
  6. mcmaster_epg-1.0.1/README.md +420 -0
  7. mcmaster_epg-1.0.1/examples/README.md +3 -0
  8. mcmaster_epg-1.0.1/examples/spiked_example.csv +61 -0
  9. mcmaster_epg-1.0.1/pyproject.toml +40 -0
  10. mcmaster_epg-1.0.1/src/mcmaster_epg/__init__.py +34 -0
  11. mcmaster_epg-1.0.1/src/mcmaster_epg/__main__.py +3 -0
  12. mcmaster_epg-1.0.1/src/mcmaster_epg/calibrate.py +372 -0
  13. mcmaster_epg-1.0.1/src/mcmaster_epg/cli.py +417 -0
  14. mcmaster_epg-1.0.1/src/mcmaster_epg/core.py +116 -0
  15. mcmaster_epg-1.0.1/src/mcmaster_epg/count_model_ci.py +43 -0
  16. mcmaster_epg-1.0.1/src/mcmaster_epg/counts.py +112 -0
  17. mcmaster_epg-1.0.1/src/mcmaster_epg/data.py +56 -0
  18. mcmaster_epg-1.0.1/src/mcmaster_epg/detection.py +251 -0
  19. mcmaster_epg-1.0.1/src/mcmaster_epg/epg.py +119 -0
  20. mcmaster_epg-1.0.1/src/mcmaster_epg/factors.py +73 -0
  21. mcmaster_epg-1.0.1/src/mcmaster_epg/herd.py +474 -0
  22. mcmaster_epg-1.0.1/src/mcmaster_epg/profile.py +353 -0
  23. mcmaster_epg-1.0.1/src/mcmaster_epg/report.py +76 -0
  24. mcmaster_epg-1.0.1/src/mcmaster_epg/validation_data.py +125 -0
  25. mcmaster_epg-1.0.1/tests/test_calibrate.py +120 -0
  26. mcmaster_epg-1.0.1/tests/test_core.py +136 -0
  27. mcmaster_epg-1.0.1/tests/test_counts.py +90 -0
  28. mcmaster_epg-1.0.1/tests/test_detection.py +142 -0
  29. mcmaster_epg-1.0.1/tests/test_epg.py +121 -0
  30. mcmaster_epg-1.0.1/tests/test_factors.py +39 -0
  31. mcmaster_epg-1.0.1/tests/test_herd.py +286 -0
  32. mcmaster_epg-1.0.1/tests/test_profile.py +118 -0
  33. mcmaster_epg-1.0.1/tests/test_report_cli.py +215 -0
  34. mcmaster_epg-1.0.1/tests/test_validation_data.py +24 -0
  35. mcmaster_epg-1.0.1/validation/CALIBRATION_REPORT.md +23 -0
  36. mcmaster_epg-1.0.1/validation/HERD_REPORT.md +171 -0
  37. mcmaster_epg-1.0.1/validation/REPORT.md +196 -0
  38. mcmaster_epg-1.0.1/validation/detection_curves.pdf +0 -0
  39. mcmaster_epg-1.0.1/validation/detection_curves.png +0 -0
  40. mcmaster_epg-1.0.1/validation/helios.sbatch +55 -0
  41. mcmaster_epg-1.0.1/validation/run_calibration_validation.py +192 -0
  42. mcmaster_epg-1.0.1/validation/run_herd_validation.py +400 -0
  43. mcmaster_epg-1.0.1/validation/run_validation.py +456 -0
@@ -0,0 +1,6 @@
1
+ __pycache__/
2
+ *.egg-info/
3
+ dist/
4
+ build/
5
+ .pytest_cache/
6
+ .venv/
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1
4
+
5
+ - Herd results: the profile-likelihood limits of the aggregation model no longer stop with a brentq error when the profile, refitted from warm starts, gives a different value at the same point on a second evaluation. Values are now computed once per point, the boundary is evaluated twice and the larger value kept, and the estimate is taken as inside the interval.
6
+ - Validation scripts: simulated data are drawn in the main process in the original order and only the estimation runs in parallel, in small chunks, so the results do not depend on the number of cores; they use every core of a Slurm job and `SIM_SCALE` may be fractional.
7
+ - `validation/helios.sbatch`: `VALIDATIONS` selects which validations run.
8
+ - Calibration and herd reports regenerated with four times more simulated studies and herds (`SIM_SCALE=4`); README updated with their numbers.
9
+
10
+ ## 1.0.0
11
+
12
+ First public release.
13
+
14
+ - EPG with exact Poisson and negative binomial confidence limits, single or replicate readings, index-of-dispersion test.
15
+ - Raynaud factors, geometric factors for other set-ups, published empirical whole-chamber factors.
16
+ - Recovery-corrected EPG for the 16 validated combinations of Kochanowski et al. (2013).
17
+ - Detection curves and LOD50/LOD95 with profile-likelihood intervals, fitted to the published spiked samples.
18
+ - Replicate planning with recovery and between-sample dispersion.
19
+ - Herd results from one count per animal: mean EPG corrected for egg loss, fraction of animals at or above an EPG threshold without distributional assumptions and under the gamma aggregation model, prevalence, and the number of animals needed to find infection.
20
+ - Method profiles: built in (Kochanowski et al. 2013), entered by hand (recovery, dispersion and their intervals), or calibrated from one's own spiked samples with profile-likelihood intervals for recovery, dispersion and detection limits, checks of proportionality, overdispersion and the detection curve, and a report; saved as JSON with the calibration data.
21
+ - Factor from the variant, any multiplier, or the volume read with the mass of faeces and the volume of flotation solution.
22
+ - Command line: `epg`, `lod`, `plan`, `batch`, `herd`, `survey`, `calibrate`, `profile`.
23
+ - Validation scripts and reports: against the published tables, and by simulation for the herd results and the calibration.
@@ -0,0 +1,50 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it and the article it accompanies."
3
+ title: "mcmaster-epg"
4
+ abstract: >-
5
+ Eggs per gram for the McMaster method, for single samples and for herds:
6
+ exact confidence limits, eggs per gram corrected for egg loss, limits of
7
+ detection, the fraction of animals above an EPG threshold with and without
8
+ an aggregation model, and survey size. The procedure is described by a
9
+ method profile that is built in (Kochanowski et al. 2013), entered by hand
10
+ or calibrated from one's own spiked samples. Validated against the published
11
+ spiking study and by simulation.
12
+ type: software
13
+ version: "1.0.1"
14
+ date-released: "2026-11-29"
15
+ license: MIT
16
+ repository-code: "https://github.com/maciejkochanowski/mcmaster-epg"
17
+ keywords:
18
+ - McMaster
19
+ - faecal egg count
20
+ - eggs per gram
21
+ - limit of detection
22
+ - veterinary parasitology
23
+ - prevalence
24
+ authors:
25
+ - family-names: Kochanowski
26
+ given-names: Maciej
27
+ email: maciej.kochanowski@piwet.pulawy.pl
28
+ orcid: "https://orcid.org/0000-0002-9982-3028"
29
+ affiliation: "Department of Bacteriology and Bacterial Animal Diseases, National Veterinary Research Institute, 57 Partyzantów Avenue, 24-100 Puławy, Poland"
30
+ references:
31
+ - type: article
32
+ title: "Analysis of the accuracy and precision of the McMaster method in detection of the eggs of Toxocara and Trichuris species (Nematoda) in dog faeces"
33
+ authors:
34
+ - family-names: Kochanowski
35
+ given-names: Maciej
36
+ - family-names: Dąbrowska
37
+ given-names: Joanna
38
+ - family-names: Karamon
39
+ given-names: Jacek
40
+ - family-names: Cencek
41
+ given-names: Tomasz
42
+ - family-names: Osiński
43
+ given-names: Zbigniew
44
+ journal: "Folia Parasitologica"
45
+ year: 2013
46
+ volume: 60
47
+ issue: 3
48
+ start: 264
49
+ end: 272
50
+ doi: "10.14411/fp.2013.030"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Maciej Kochanowski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,443 @@
1
+ Metadata-Version: 2.5
2
+ Name: mcmaster-epg
3
+ Version: 1.0.1
4
+ Summary: Eggs per gram for the McMaster method, for samples and herds: exact confidence limits, correction for egg loss, detection limits, herd fractions above EPG thresholds and survey size, with method profiles built in, entered by hand or calibrated from one's own spiked samples
5
+ Project-URL: Repository, https://github.com/maciejkochanowski/mcmaster-epg
6
+ Author-email: Maciej Kochanowski <maciej.kochanowski@piwet.pulawy.pl>
7
+ License: MIT
8
+ License-File: LICENSE
9
+ Keywords: McMaster,calibration,eggs per gram,faecal egg count,limit of detection,method validation,parasitology,partial identification,prevalence,veterinary
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: numpy>=1.22
16
+ Requires-Dist: scipy>=1.8
17
+ Provides-Extra: test
18
+ Requires-Dist: pytest; extra == 'test'
19
+ Provides-Extra: validation
20
+ Requires-Dist: matplotlib; extra == 'validation'
21
+ Requires-Dist: scienceplots; extra == 'validation'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # mcmaster-epg
25
+
26
+ Eggs per gram (EPG) for the McMaster method, for single samples and for
27
+ herds, with the egg loss and variability of the procedure taken into account.
28
+ For a sample: exact confidence limits, EPG corrected for egg loss, and limits
29
+ of detection. For a herd examined with one count per animal: the mean EPG,
30
+ the fraction of animals at or above an EPG threshold (with and without an
31
+ aggregation model), and the number of animals to examine to find infection.
32
+
33
+ Everything the calculations need to know about a procedure is held in a
34
+ **method profile**: the multiplication factor, the recovery of eggs, the
35
+ dispersion of counts between samples, their uncertainty, and the
36
+ spiked-sample results behind the detection curve. A profile is
37
+
38
+ - **built in** for the combinations validated by Kochanowski et al. (2013):
39
+ Raynaud's modification (2 g of faeces in 28 ml of saturated MgSO4, McMaster
40
+ chamber or flotation slide), eggs of *Toxocara canis* and *Trichuris* in
41
+ dog faeces and *Ascaris suum* in dog and pig faeces
42
+ (https://doi.org/10.14411/fp.2013.030);
43
+ - **entered by hand**, for example from a published validation of another
44
+ procedure (`--recovery`, `--k` and their intervals);
45
+ - **calibrated** from one's own spiked samples (`mcmaster-epg calibrate`),
46
+ for any chamber, dilution, flotation solution, host and parasite.
47
+
48
+ For faecal egg count reduction tests and hierarchical models use `eggCounts`,
49
+ `bayescount` or fecrt.com; `mcmaster-epg` gives them the raw count and
50
+ correction factor they expect (see [Output](#output)).
51
+
52
+ ## Installation
53
+
54
+ ```bash
55
+ pip install mcmaster-epg
56
+ ```
57
+
58
+ Python 3.10 or later; NumPy and SciPy are installed with it.
59
+
60
+ ## Command line
61
+
62
+ ```bash
63
+ mcmaster-epg epg 7 --variant whole_chamber
64
+ # EPG 105 (95% CI 42.2 to 216.3)
65
+
66
+ mcmaster-epg epg 6 --variant whole_chamber --species toxocara_canis
67
+ # EPG 90 (95% CI 33.0 to 195.9)
68
+ # Corrected EPG 276 (95% CI 80 to 1249), factor 46 (published factor)
69
+ # interval includes between-sample dispersion k = 4.4
70
+ # LOD50 25 EPG (14 to 37), LOD95 154 EPG (111 to 240); published LOD 25 EPG
71
+
72
+ mcmaster-epg epg 0 0 0 40 --variant one_grid # replicate readings
73
+ mcmaster-epg lod --variant one_grid --probability 0.95
74
+ mcmaster-epg lod --variant whole_chamber --species toxocara_canis
75
+ mcmaster-epg plan 150 --variant whole_chamber --cv 0.2 --species toxocara_canis
76
+ mcmaster-epg batch samples.csv > results.csv
77
+ ```
78
+
79
+ Every command takes the method in the same way.
80
+
81
+ The factor: `--variant` (`one_grid`, `two_grids`, `whole_chamber`,
82
+ `flotation_slide`, Raynaud's factors 100, 50, 15, 7), `--multiplier` (any
83
+ factor), or `--counted-ml` with `--faeces-g` and `--flotation-ml` (the factor
84
+ is computed as (faeces + flotation volume) / (faeces x volume read)).
85
+
86
+ Egg loss and dispersion, from one source: `--profile FILE`, the built-in
87
+ `--species` (with `--variant`; `--matrix pig` for pig faeces), or `--recovery`
88
+ and `--k` entered by hand, optionally with `--recovery-ci LOW HIGH` and
89
+ `--k-ci LOW HIGH` (95% intervals; `inf` allowed as the upper limit of k).
90
+ Without any of them the nominal method is used: no egg loss, Poisson counts.
91
+ `epg --json` prints every field listed under [Output](#output).
92
+
93
+ The CSV for `batch` has the columns `sample_id,counts[,variant,species,matrix]`;
94
+ replicate readings of one sample are separated by `;`. Give the method either
95
+ in the file (per row) or on the command line (for all rows).
96
+
97
+ ## Your own method
98
+
99
+ Spike faeces free of eggs with known numbers of eggs at several levels,
100
+ prepare and read each sample as in routine work, and record one row per
101
+ sample:
102
+
103
+ ```text
104
+ sample,level,count
105
+ S01,25,0
106
+ S02,25,2
107
+ ...
108
+ ```
109
+
110
+ `level` is eggs per gram added, `count` the eggs counted in one reading
111
+ (comma, semicolon or tab separated; decimal comma accepted). Then
112
+
113
+ ```bash
114
+ mcmaster-epg calibrate examples/spiked_example.csv --multiplier 50 \
115
+ --name "example lab, two grids" --out lab.json --report lab.md
116
+ ```
117
+
118
+ writes the profile `lab.json` (with the calibration data in it) and a report
119
+ `lab.md`: recovery, the corrected factor, the dispersion k and LOD50 and LOD95,
120
+ all with profile-likelihood intervals; a test of proportionality of the mean
121
+ count to the level; a test of overdispersion; the detection curve fitted to
122
+ the share of positive samples as an independent check, with its goodness of
123
+ fit; and observed against predicted values at every level. For the simulated
124
+ example file (true recovery 0.6, k = 6, LOD50 65 and LOD95 324 eggs/g):
125
+
126
+ ```text
127
+ | Recovery | 0.621 | 0.485 to 0.798 (profile likelihood) |
128
+ | Corrected factor (factor / recovery) | 80.6 | 62.6 to 103.1 |
129
+ | Dispersion k | 2.46 | 1.27 to 4.99 (profile likelihood) |
130
+ | LOD50 (eggs/g) | 64.5 | 50.2 to 86.3 (count model, profile likelihood) |
131
+ | LOD95 (eggs/g) | 471.6 | 306.4 to 1016.8 (count model, profile likelihood) |
132
+ ```
133
+
134
+ In this draw the interval of k misses the true value, as a 95% interval does
135
+ in about one study in twenty; the other intervals contain theirs.
136
+
137
+ Every command then uses the profile:
138
+
139
+ ```bash
140
+ mcmaster-epg epg 3 --profile lab.json
141
+ # EPG 150 (95% CI 30.9 to 438.4)
142
+ # Corrected EPG 242 (95% CI 40 to 2218), factor 80.6 (calibrated recovery)
143
+ # interval includes between-sample dispersion k = 2.5
144
+ # LOD50 65 EPG (50 to 86), LOD95 472 EPG (306 to 1017)
145
+
146
+ mcmaster-epg herd --file animals.csv --profile lab.json --threshold 200
147
+ mcmaster-epg survey --profile lab.json --prevalence 0.1 --threshold 200
148
+ ```
149
+
150
+ Parameters from a publication can be entered directly, or saved as a profile:
151
+
152
+ ```bash
153
+ mcmaster-epg epg 3 --multiplier 50 --recovery 0.6 --recovery-ci 0.5 0.7 --k 6
154
+ mcmaster-epg profile --multiplier 50 --recovery 0.6 --recovery-ci 0.5 0.7 --k 6 --out paper.json
155
+ mcmaster-epg profile --variant whole_chamber --species toxocara_canis --out builtin.json
156
+ ```
157
+
158
+ Design of the spiking study: the more levels near the expected limit of
159
+ detection and the more samples per level, the narrower the limits. Eight
160
+ levels with 20 samples each, as in the built-in study, give recovery to about
161
+ plus or minus 12% (true recovery 0.4, k = 4.4); five levels with 10 samples,
162
+ about plus or minus 21% (see [Validation](#validation)). Counts must come from independently prepared
163
+ samples, not from re-reading one chamber.
164
+
165
+ ## Herds
166
+
167
+ One McMaster count per animal, for a herd, farm or kennel:
168
+
169
+ ```bash
170
+ mcmaster-epg herd 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 4 5 6 7 8 11 18 22 \
171
+ --variant whole_chamber --species ascaris_suum --matrix pig --threshold 50 150
172
+ # 30 animals, 10 positive (33.3%, 95% CI 17.3% to 52.8%)
173
+ # Mean EPG 57 (95% CI 19 to 274), factor 20.3; aggregation between animals k 0.14
174
+ # Without assumptions about the distribution of EPG among animals:
175
+ # infected (any eggs): at least 17.3%; McMaster counts give no upper limit
176
+ # true EPG >= 50: 1.6% to 67.3% of animals (95% CI; detection at 50 EPG 0.92)
177
+ # true EPG >= 150: 0.0% to 59.9% of animals (95% CI; detection at 150 EPG 1.00)
178
+ # Gamma aggregation model (negative binomial between animals):
179
+ # infected 35.4% (17.3% to 100.0%); mean EPG of infected 160, shape 1.59
180
+ # true EPG >= 50: 29.3% (12.8% to 51.1%)
181
+ # true EPG >= 150: 15.1% (4.1% to 35.5%)
182
+
183
+ mcmaster-epg survey --variant whole_chamber --species toxocara_canis --prevalence 0.1 --threshold 50
184
+ # 48 animals: a positive is found with probability 0.95 if at least 10% of the herd
185
+ # has 50 EPG or more (detection at 50 EPG at least 0.62)
186
+ ```
187
+
188
+ `--file` reads the counts from a text file or from the `counts` column of a CSV.
189
+
190
+ What the results mean:
191
+
192
+ - **Mean EPG** is corrected for egg loss (mean count x factor / recovery of the
193
+ count model), with a negative binomial profile-likelihood interval.
194
+ - **Fraction of animals at or above a threshold** (for example a treatment
195
+ threshold), first without any assumption about how EPG is distributed among
196
+ the animals. These limits hold for every distribution, so they are wide;
197
+ they show what the counts alone establish.
198
+ - **The same under the gamma aggregation model**, the usual negative binomial
199
+ model of parasite burdens. Narrower, but valid only as far as the model
200
+ holds (see [Validation](#validation)).
201
+ - **Prevalence of infection** (any EPG above 0) has no upper limit without
202
+ assumptions: an animal with 1 EPG is almost always negative, so negative
203
+ results never exclude that all animals are infected. The aggregation model
204
+ gives an estimate, but its upper limit is often 100%.
205
+ - **`survey`** gives the number of animals to examine so that one positive is
206
+ found if at least the given fraction of the herd has the given EPG or more.
207
+ No distribution of EPG is assumed.
208
+
209
+ Without a profile (`--species`, `--profile` or `--recovery`) the nominal
210
+ method is used (no egg loss, Poisson counts), which overestimates detection;
211
+ the output says so. Without `--recovery-ci` and `--k-ci`, entered parameters
212
+ are treated as known and the herd intervals do not include their uncertainty.
213
+
214
+ ## Python
215
+
216
+ ```python
217
+ from mcmaster_epg import RAYNAUD_MULTIPLIER, epg, epg_ci, detection_limit, replicates_for_cv
218
+
219
+ factor = RAYNAUD_MULTIPLIER["whole_chamber"] # 15
220
+ epg(7, factor) # 105
221
+ epg_ci(7, factor) # (42.2, 216.3), exact 95% limits
222
+ detection_limit(factor, probability=0.95) # 44.9, Poisson counts only
223
+ replicates_for_cv(150, factor, target_cv=0.1) # 10, Poisson counts only
224
+
225
+ from mcmaster_epg import interpret, fitted_limits
226
+ interpret(6, "whole_chamber", species="toxocara_canis", matrix="dog") # dict, see below
227
+ fitted_limits("toxocara_canis", "dog", "whole_chamber")
228
+ # {'lod50': (25.1, 14.2, 37.2), 'lod95': (154, 111, 240)} (rounded)
229
+
230
+ from mcmaster_epg import multiplier
231
+ multiplier(mass_g=2, suspension_ml=30, counted_ml=0.15) # 100, for other set-ups
232
+
233
+ # method profiles
234
+ from mcmaster_epg.profile import builtin_profile, manual_profile, load_profile
235
+ from mcmaster_epg.calibrate import calibrate, read_spiked
236
+ from mcmaster_epg.report import interpret_profile
237
+ from mcmaster_epg.herd import summarise_herd
238
+
239
+ levels, counts = read_spiked("examples/spiked_example.csv")
240
+ lab = calibrate(levels, counts, factor=50, name="example lab").profile
241
+ interpret_profile([3], lab) # dict, see below
242
+ summarise_herd([0, 0, 1, 5], thresholds=(200,), profile=lab)
243
+ paper = manual_profile(50, recovery=0.6, k=6, recovery_ci=(0.5, 0.7))
244
+ ```
245
+
246
+ ## Output
247
+
248
+ | Field | Meaning |
249
+ |---|---|
250
+ | `total_count`, `readings`, `cf_total` | eggs counted over all readings, number of readings, and the factor for the summed count (`total_count * cf_total = epg_nominal`). These are the raw count and correction factor of the WAAVP 2023 guideline and of `eggCounts` (`rawCounts = TRUE`, `preCF`); `eggCounts` needs an integer factor. |
251
+ | `epg_nominal`, `epg_nominal_ci` | count x Raynaud factor (100, 50, 15, 7) with the exact Poisson interval. Counting error only; no correction for egg loss. |
252
+ | `epg_corrected`, `epg_corrected_ci` | count x recovery-corrected factor. Whole chamber: the published factor (46, 28, 21). Other variants: nominal factor / recovery of the count model. The interval includes the between-sample variation estimated from the spiked samples (`dispersion_k`) where it was detected. |
253
+ | `correction_source` | `published factor` or `count model`. |
254
+ | `quantitative_range`, `within_quantitative_range` | range of levels on which the published whole-chamber regression was fitted, and whether the corrected EPG lies in it. |
255
+ | `published_lod` | limit of detection from Table 4 of the paper. |
256
+ | `lod50`, `lod95` and their intervals | EPG detected in 50% and 95% of single examinations, from the detection curve fitted to the spiked samples. `lod95_extrapolated` marks values above 300 eggs/g, the highest tested level. |
257
+ | `dispersion_index`, `dispersion_p` | for replicate readings: Poisson index of dispersion and its p-value (Torgerson et al. 2012). A small p means the Poisson interval is too narrow. |
258
+
259
+ ## Methods
260
+
261
+ **Calibration.** Counts of the spiked samples are modelled as negative
262
+ binomial with mean recovery x level / factor and dispersion k (Poisson when k
263
+ is infinite), fitted by maximum likelihood. Recovery, k and the limits of
264
+ detection (LOD_p = factor x m_p(k) / recovery, with m_p(k) the mean count at
265
+ which P(count >= 1) = p) get profile-likelihood intervals, the other
266
+ parameter profiled out. The parameter ranges that the herd calculations use
267
+ are profile-likelihood intervals at the levels they need (90% to 98.75%),
268
+ stored in the profile with the calibration data. Proportionality is tested
269
+ against log mean = a + b log level (likelihood ratio, b = 1), overdispersion
270
+ against Poisson (likelihood ratio, half the chi-square tail at the boundary).
271
+ The detection curve below is fitted to the share of positive samples only and
272
+ is reported as an independent check, with a parametric-bootstrap
273
+ goodness-of-fit test. Entered 95% intervals are converted to other levels
274
+ assuming a normal distribution of the logarithm of the parameter.
275
+
276
+ **Factors.** `geometric_factor(counted_ml, faeces_g, flotation_ml)` gives the
277
+ factor for any dilution and counted volume; it reproduces 100 (0.15 ml) and
278
+ 50 (0.30 ml).
279
+
280
+ **Whole-chamber factor.** The nominal factor 15 corresponds to 1.0 ml, while
281
+ the chamber holds 1.5 ml (geometric factor 10). The spiked samples fit 15 better
282
+ than 10: with 15 the detection data of the three chamber variants are
283
+ compatible with one recovery per species in all four groups, with 10 in two of
284
+ four. In the count data the whole chamber still recovers less than the grids
285
+ for Trichuris and Ascaris (validation report, section 4). The paper notes that
286
+ eggs gather under the grids.
287
+
288
+ **Flotation slide.** The nominal factor 7 underestimates about five- to
289
+ nine-fold in the spiked samples (effective factor 38 to 65). Use the corrected
290
+ EPG for this variant.
291
+
292
+ **Published whole-chamber factors.** They are 1/slope of regressions with a
293
+ positive intercept, so as plain multipliers they overestimate, most at low
294
+ counts (validation report, section 4).
295
+
296
+ **Intervals.** Poisson: exact (Garwood). With dispersion k (variance = mean +
297
+ mean^2/k): exact inversion of the negative binomial distribution; replicate
298
+ readings are pooled. The Poisson interval is too narrow when samples differ
299
+ more than counting error explains (validation report, section 6).
300
+
301
+ **Detection curve.** POD = 1 - exp(-ln 2 x (EPG / LOD50)^slope), fitted by
302
+ binomial maximum likelihood with profile-likelihood intervals. Slope 1 is the
303
+ complementary log-log model of Wilrich and Wilrich (2009, J AOAC Int
304
+ 92:1763-1772) used in ISO 16140-2; the spiked samples require a slope below 1
305
+ in most combinations. `detection_limit` and `lod` without `--species` give the
306
+ Poisson (slope 1) limit of the nominal method, which is lower than the
307
+ observed one.
308
+
309
+ **Count model.** Negative binomial counts with mean recovery x EPG / factor,
310
+ fitted to the published mean and SD of ln(count + 1).
311
+
312
+ **Herd limits without assumptions.** For a count c, let q_c be the fraction
313
+ of animals with a count of at least c and s_c the probability of such a count
314
+ at the threshold EPG t. The probability rises with EPG, so for every
315
+ distribution of EPG among the animals the fraction at or above t lies between
316
+ (q_c - s_c)/(1 - s_c) and q_c/s_c. `fraction_above` uses several counts c
317
+ (chosen from the design, not from the data), exact binomial intervals for
318
+ their q_c with a Bonferroni split, and a linear programme over all
319
+ distributions of EPG consistent with those intervals; the limits are the
320
+ smallest and largest fraction at or above t. Uncertainty of recovery and k
321
+ from the spiked samples is included through bootstrap percentiles
322
+ (`count_model_ci`): a larger recovery rescales the EPG axis and lowers both
323
+ limits, so the lower limit uses the upper end of the recovery range and the
324
+ upper limit its lower end. Half of 1 - conf goes to the herd data, half to the
325
+ parameters. Assumes one examination per animal, independent examinations and
326
+ no false positives.
327
+
328
+ **Aggregation model.** A fraction of the animals is infected and their EPG
329
+ follows a gamma distribution (shape and mean free); counts then follow the
330
+ count model of the combination (within-sample variation by Gauss-Laguerre
331
+ quadrature). Fitted by maximum likelihood; intervals for prevalence and for
332
+ the fraction at or above t are profile-likelihood intervals, with the
333
+ parameter uncertainty handled as above.
334
+
335
+ **Survey size.** Every animal at or above t is positive with probability at
336
+ least s_1(t), taken at the least favourable end of the 95% parameter range, so
337
+ n = ln(1 - conf) / ln(1 - fraction x s_1(t)) whatever the other animals carry.
338
+
339
+ **Replicate planning.** The CV of the mean of n independent counts is
340
+ sqrt((1/mean + 1/k) / n). With `--species` the recovery and k of the count
341
+ model are used. k describes variation between independently prepared
342
+ samples, so the replicates are separate preparations, not re-readings of one
343
+ chamber.
344
+
345
+ ## Validation
346
+
347
+ `python validation/run_validation.py` writes `validation/REPORT.md` and
348
+ `validation/detection_curves.png` (needs `pip install mcmaster-epg[validation]`);
349
+ `python validation/run_herd_validation.py` writes `validation/HERD_REPORT.md`
350
+ (about an hour on two cores) and `python validation/run_calibration_validation.py`
351
+ writes `validation/CALIBRATION_REPORT.md` (about five minutes); both use the
352
+ available cores (`SLURM_CPUS_PER_TASK` on a cluster, otherwise up to 8). On a
353
+ cluster, `sbatch validation/helios.sbatch` runs all three with every core of
354
+ the job and `SIM_SCALE` times more simulated herds and studies (default 4
355
+ there; a few minutes on 192 cores), and `VALIDATIONS="calibration herd"`
356
+ selects some of them. The calibration and herd reports in `validation/` come
357
+ from such a run with `SIM_SCALE=4`.
358
+ `pytest` runs the tests. Main results (all 16 combinations of egg type, faeces
359
+ and counting variant in the paper):
360
+
361
+ - the published tables are internally consistent: Table 4 limits are
362
+ reproduced from Table 3 in 16 of 16 combinations;
363
+ - the two-parameter detection curve is not rejected in 16 of 16 combinations
364
+ (parametric bootstrap of the deviance), and it predicts left-out spiking
365
+ levels with a mean error of 6.8 percentage points, against 5.7 from
366
+ binomial sampling error alone and 11.9 for the textbook Poisson model;
367
+ - curves fitted to Ascaris suum in dog faeces predict the independent pig
368
+ samples with errors of 2.9 to 9.4 percentage points;
369
+ - the Poisson interval keeps its 95% coverage only if counts are Poisson; at
370
+ the dispersion found for Toxocara canis (k = 4.4) its mean coverage falls to
371
+ 74%, while the negative binomial interval keeps 95%.
372
+
373
+ Calibration (`validation/CALIBRATION_REPORT.md`; 2000 simulated spiking
374
+ studies per row, true recovery 0.40 to 0.74, k from 1.5 to Poisson; Monte
375
+ Carlo SE 0.5% at 95%):
376
+
377
+ - with eight levels of 20 samples, the 95% intervals of recovery, k, LOD50
378
+ and LOD95 contain the truth in 94.4% to 98.0% of studies, and the 98.75%
379
+ ranges used by the herd calculations in 98.3% to 99.5%;
380
+ - with five levels of 10 samples, the 95% interval of recovery contains it in
381
+ 93.8% to 95.4% and its 98.75% range in 98.5% to 98.6%; the other intervals
382
+ stay at 94.3% or more;
383
+ - LOD95 from the count model keeps 94.3% or more, while the detection curve
384
+ fitted to positive results alone falls to 91.7%, which is why the count
385
+ model gives the limits and the curve is only a check.
386
+
387
+ Herd results (`validation/HERD_REPORT.md`; simulated herds of 30 and 100
388
+ animals, 400 to 1200 herds per row, with recovery and k redrawn for every herd
389
+ from a bootstrap of the spiking design):
390
+
391
+ - limits without assumptions contain the true fraction in at least 99.7% of
392
+ herds in every scenario, including the least favourable distributions; they
393
+ are wide (mean width 0.38 to 1.00 with 100 animals), and 0 to 0.53 of that
394
+ width remains even with unlimited animals, because a single McMaster count
395
+ cannot place animals near the threshold on one side of it;
396
+ - under the gamma aggregation model, when the model holds, the intervals are
397
+ narrower (mean width 0.18 to 0.54 with 100 animals) with bias below 0.05;
398
+ coverage is at least 0.97 with 100 animals but only 0.909 to 0.959 with 30
399
+ animals (lowest under strong aggregation, shape 0.5, and at 150 EPG in the
400
+ moderately infected herd); when the model does not hold
401
+ (a bimodal herd) the estimate is biased by up to 0.29 and coverage falls to
402
+ 0, so compare it with the limits without assumptions;
403
+ - prevalence of infection under the aggregation model: coverage 0.978 to
404
+ 0.994 where the model holds, but the upper limit is 100% in 60% to 98% of
405
+ those herds;
406
+ - the mean EPG interval covers the truth in at least 98.3% of herds, with a
407
+ median estimate within 10% of the truth;
408
+ - planned survey sizes find a positive in at least 95.3% of least favourable
409
+ herds (target 95%; Monte Carlo SE 0.1%).
410
+
411
+ A model limit equal to the published one is not a usable criterion: the
412
+ published limit is read from 20 replicates on a grid of eight levels, and even
413
+ an exactly true curve would match it in only about 9 of 16 combinations
414
+ (simulation). The fitted curve matches it in 10 of 16 and is within one level
415
+ in 16 of 16.
416
+
417
+ ## Limits
418
+
419
+ - The built-in profiles come from one laboratory, one chamber type, three egg
420
+ types and dog and pig faeces, and are fitted to the published summary
421
+ tables; for other procedures calibrate from your own spiked samples or enter
422
+ published parameters.
423
+ - Detection limits above the highest spiking level (300 eggs/g for the
424
+ built-in profiles) are extrapolations; the output marks them.
425
+ - Calibration assumes that recovery does not depend on the level (tested) and
426
+ that each spiked sample was prepared independently (not tested).
427
+ - Herd results assume one examination per animal, independent examinations,
428
+ no false positives, and animals whose egg loss resembles that of the spiked
429
+ samples. Intervals of the aggregation model are somewhat too narrow with 30
430
+ animals (coverage 0.909 to 0.959 for nominal 0.95).
431
+
432
+ ## How to cite
433
+
434
+ Kochanowski M. mcmaster-epg, version 1.0.1. See `CITATION.cff`.
435
+
436
+ Kochanowski M, Dąbrowska J, Karamon J, Cencek T, Osiński Z. Analysis of the
437
+ accuracy and precision of the McMaster method in detection of the eggs of
438
+ *Toxocara* and *Trichuris* species (Nematoda) in dog faeces. Folia
439
+ Parasitologica 2013; 60(3): 264-272. https://doi.org/10.14411/fp.2013.030
440
+
441
+ ## Licence
442
+
443
+ MIT