Skip to main content

mcmaster-epg

Eggs per gram (EPG) for the McMaster method, for single samples and for herds, with the egg loss and variability of the procedure taken into account. For a sample: exact confidence limits, EPG corrected for egg loss, and limits of detection. For a herd examined with one count per animal: the mean EPG, the fraction of animals at or above an EPG threshold (with and without an aggregation model), and the number of animals to examine to find infection.

Everything the calculations need to know about a procedure is held in a method profile: the multiplication factor, the recovery of eggs, the dispersion of counts between samples, their uncertainty, and the spiked-sample results behind the detection curve. A profile is

  • built in for the combinations validated by Kochanowski et al. (2013): Raynaud's modification (2 g of faeces in 28 ml of saturated MgSO4, McMaster chamber or flotation slide), eggs of Toxocara canis and Trichuris in dog faeces and Ascaris suum in dog and pig faeces (https://doi.org/10.14411/fp.2013.030);
  • entered by hand, for example from a published validation of another procedure (--recovery, --k and their intervals);
  • calibrated from one's own spiked samples (mcmaster-epg calibrate), for any chamber, dilution, flotation solution, host and parasite.

For faecal egg count reduction tests and hierarchical models use eggCounts, bayescount or fecrt.com; mcmaster-epg gives them the raw count and correction factor they expect (see Output).

Installation

pip install mcmaster-epg

Python 3.10 or later; NumPy and SciPy are installed with it.

Command line

mcmaster-epg epg 7 --variant whole_chamber
# EPG 105 (95% CI 42.2 to 216.3)

mcmaster-epg epg 6 --variant whole_chamber --species toxocara_canis
# EPG 90 (95% CI 33.0 to 195.9)
# Corrected EPG 276 (95% CI 80 to 1249), factor 46 (published factor)
#   interval includes between-sample dispersion k = 4.4
# LOD50 25 EPG (14 to 37), LOD95 154 EPG (111 to 240); published LOD 25 EPG

mcmaster-epg epg 0 0 0 40 --variant one_grid      # replicate readings
mcmaster-epg lod --variant one_grid --probability 0.95
mcmaster-epg lod --variant whole_chamber --species toxocara_canis
mcmaster-epg plan 150 --variant whole_chamber --cv 0.2 --species toxocara_canis
mcmaster-epg batch samples.csv > results.csv

Every command takes the method in the same way.

The factor: --variant (one_grid, two_grids, whole_chamber, flotation_slide, Raynaud's factors 100, 50, 15, 7), --multiplier (any factor), or --counted-ml with --faeces-g and --flotation-ml (the factor is computed as (faeces + flotation volume) / (faeces x volume read)).

Egg loss and dispersion, from one source: --profile FILE, the built-in --species (with --variant; --matrix pig for pig faeces), or --recovery and --k entered by hand, optionally with --recovery-ci LOW HIGH and --k-ci LOW HIGH (95% intervals; inf allowed as the upper limit of k). Without any of them the nominal method is used: no egg loss, Poisson counts. epg --json prints every field listed under Output.

The CSV for batch has the columns sample_id,counts[,variant,species,matrix]; replicate readings of one sample are separated by ;. Give the method either in the file (per row) or on the command line (for all rows).

Your own method

Spike faeces free of eggs with known numbers of eggs at several levels, prepare and read each sample as in routine work, and record one row per sample:

sample,level,count
S01,25,0
S02,25,2
...

level is eggs per gram added, count the eggs counted in one reading (comma, semicolon or tab separated; decimal comma accepted). Then

mcmaster-epg calibrate examples/spiked_example.csv --multiplier 50 \
    --name "example lab, two grids" --out lab.json --report lab.md

writes the profile lab.json (with the calibration data in it) and a report lab.md: recovery, the corrected factor, the dispersion k and LOD50 and LOD95, all with profile-likelihood intervals; a test of proportionality of the mean count to the level; a test of overdispersion; the detection curve fitted to the share of positive samples as an independent check, with its goodness of fit; and observed against predicted values at every level. For the simulated example file (true recovery 0.6, k = 6, LOD50 65 and LOD95 324 eggs/g):

| Recovery | 0.621 | 0.485 to 0.798 (profile likelihood) |
| Corrected factor (factor / recovery) | 80.6 | 62.6 to 103.1 |
| Dispersion k | 2.46 | 1.27 to 4.99 (profile likelihood) |
| LOD50 (eggs/g) | 64.5 | 50.2 to 86.3 (count model, profile likelihood) |
| LOD95 (eggs/g) | 471.6 | 306.4 to 1016.8 (count model, profile likelihood) |

In this draw the interval of k misses the true value, as a 95% interval does in about one study in twenty; the other intervals contain theirs.

Every command then uses the profile:

mcmaster-epg epg 3 --profile lab.json
# EPG 150 (95% CI 30.9 to 438.4)
# Corrected EPG 242 (95% CI 40 to 2218), factor 80.6 (calibrated recovery)
#   interval includes between-sample dispersion k = 2.5
# LOD50 65 EPG (50 to 86), LOD95 472 EPG (306 to 1017)

mcmaster-epg herd --file animals.csv --profile lab.json --threshold 200
mcmaster-epg survey --profile lab.json --prevalence 0.1 --threshold 200

Parameters from a publication can be entered directly, or saved as a profile:

mcmaster-epg epg 3 --multiplier 50 --recovery 0.6 --recovery-ci 0.5 0.7 --k 6
mcmaster-epg profile --multiplier 50 --recovery 0.6 --recovery-ci 0.5 0.7 --k 6 --out paper.json
mcmaster-epg profile --variant whole_chamber --species toxocara_canis --out builtin.json

Design of the spiking study: the more levels near the expected limit of detection and the more samples per level, the narrower the limits. Eight levels with 20 samples each, as in the built-in study, give recovery to about plus or minus 12% (true recovery 0.4, k = 4.4); five levels with 10 samples, about plus or minus 21% (see Validation). Counts must come from independently prepared samples, not from re-reading one chamber.

Herds

One McMaster count per animal, for a herd, farm or kennel:

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 \
    --variant whole_chamber --species ascaris_suum --matrix pig --threshold 50 150
# 30 animals, 10 positive (33.3%, 95% CI 17.3% to 52.8%)
# Mean EPG 57 (95% CI 19 to 274), factor 20.3; aggregation between animals k 0.14
# Without assumptions about the distribution of EPG among animals:
#   infected (any eggs): at least 17.3%; McMaster counts give no upper limit
#   true EPG >= 50: 1.6% to 67.3% of animals (95% CI; detection at 50 EPG 0.92)
#   true EPG >= 150: 0.0% to 59.9% of animals (95% CI; detection at 150 EPG 1.00)
# Gamma aggregation model (negative binomial between animals):
#   infected 35.4% (17.3% to 100.0%); mean EPG of infected 160, shape 1.59
#   true EPG >= 50: 29.3% (12.8% to 51.1%)
#   true EPG >= 150: 15.1% (4.1% to 35.5%)

mcmaster-epg survey --variant whole_chamber --species toxocara_canis --prevalence 0.1 --threshold 50
# 48 animals: a positive is found with probability 0.95 if at least 10% of the herd
# has 50 EPG or more (detection at 50 EPG at least 0.62)

--file reads the counts from a text file or from the counts column of a CSV.

What the results mean:

  • Mean EPG is corrected for egg loss (mean count x factor / recovery of the count model), with a negative binomial profile-likelihood interval.
  • Fraction of animals at or above a threshold (for example a treatment threshold), first without any assumption about how EPG is distributed among the animals. These limits hold for every distribution, so they are wide; they show what the counts alone establish.
  • The same under the gamma aggregation model, the usual negative binomial model of parasite burdens. Narrower, but valid only as far as the model holds (see Validation).
  • Prevalence of infection (any EPG above 0) has no upper limit without assumptions: an animal with 1 EPG is almost always negative, so negative results never exclude that all animals are infected. The aggregation model gives an estimate, but its upper limit is often 100%.
  • survey gives the number of animals to examine so that one positive is found if at least the given fraction of the herd has the given EPG or more. No distribution of EPG is assumed.

Without a profile (--species, --profile or --recovery) the nominal method is used (no egg loss, Poisson counts), which overestimates detection; the output says so. Without --recovery-ci and --k-ci, entered parameters are treated as known and the herd intervals do not include their uncertainty.

Python

from mcmaster_epg import RAYNAUD_MULTIPLIER, epg, epg_ci, detection_limit, replicates_for_cv

factor = RAYNAUD_MULTIPLIER["whole_chamber"]      # 15
epg(7, factor)                                    # 105
epg_ci(7, factor)                                 # (42.2, 216.3), exact 95% limits
detection_limit(factor, probability=0.95)         # 44.9, Poisson counts only
replicates_for_cv(150, factor, target_cv=0.1)     # 10, Poisson counts only

from mcmaster_epg import interpret, fitted_limits
interpret(6, "whole_chamber", species="toxocara_canis", matrix="dog")   # dict, see below
fitted_limits("toxocara_canis", "dog", "whole_chamber")
# {'lod50': (25.1, 14.2, 37.2), 'lod95': (154, 111, 240)}  (rounded)

from mcmaster_epg import multiplier
multiplier(mass_g=2, suspension_ml=30, counted_ml=0.15)   # 100, for other set-ups

# method profiles
from mcmaster_epg.profile import builtin_profile, manual_profile, load_profile
from mcmaster_epg.calibrate import calibrate, read_spiked
from mcmaster_epg.report import interpret_profile
from mcmaster_epg.herd import summarise_herd

levels, counts = read_spiked("examples/spiked_example.csv")
lab = calibrate(levels, counts, factor=50, name="example lab").profile
interpret_profile([3], lab)                                  # dict, see below
summarise_herd([0, 0, 1, 5], thresholds=(200,), profile=lab)
paper = manual_profile(50, recovery=0.6, k=6, recovery_ci=(0.5, 0.7))

Output

Field Meaning
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.
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.
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.
correction_source published factor or count model.
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.
published_lod limit of detection from Table 4 of the paper.
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.
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.

Methods

Calibration. Counts of the spiked samples are modelled as negative binomial with mean recovery x level / factor and dispersion k (Poisson when k is infinite), fitted by maximum likelihood. Recovery, k and the limits of detection (LOD_p = factor x m_p(k) / recovery, with m_p(k) the mean count at which P(count >= 1) = p) get profile-likelihood intervals, the other parameter profiled out. The parameter ranges that the herd calculations use are profile-likelihood intervals at the levels they need (90% to 98.75%), stored in the profile with the calibration data. Proportionality is tested against log mean = a + b log level (likelihood ratio, b = 1), overdispersion against Poisson (likelihood ratio, half the chi-square tail at the boundary). The detection curve below is fitted to the share of positive samples only and is reported as an independent check, with a parametric-bootstrap goodness-of-fit test. Entered 95% intervals are converted to other levels assuming a normal distribution of the logarithm of the parameter.

Factors. geometric_factor(counted_ml, faeces_g, flotation_ml) gives the factor for any dilution and counted volume; it reproduces 100 (0.15 ml) and 50 (0.30 ml).

Whole-chamber factor. The nominal factor 15 corresponds to 1.0 ml, while the chamber holds 1.5 ml (geometric factor 10). The spiked samples fit 15 better than 10: with 15 the detection data of the three chamber variants are compatible with one recovery per species in all four groups, with 10 in two of four. In the count data the whole chamber still recovers less than the grids for Trichuris and Ascaris (validation report, section 4). The paper notes that eggs gather under the grids.

Flotation slide. The nominal factor 7 underestimates about five- to nine-fold in the spiked samples (effective factor 38 to 65). Use the corrected EPG for this variant.

Published whole-chamber factors. They are 1/slope of regressions with a positive intercept, so as plain multipliers they overestimate, most at low counts (validation report, section 4).

Intervals. Poisson: exact (Garwood). With dispersion k (variance = mean + mean^2/k): exact inversion of the negative binomial distribution; replicate readings are pooled. The Poisson interval is too narrow when samples differ more than counting error explains (validation report, section 6).

Detection curve. POD = 1 - exp(-ln 2 x (EPG / LOD50)^slope), fitted by binomial maximum likelihood with profile-likelihood intervals. Slope 1 is the complementary log-log model of Wilrich and Wilrich (2009, J AOAC Int 92:1763-1772) used in ISO 16140-2; the spiked samples require a slope below 1 in most combinations. detection_limit and lod without --species give the Poisson (slope 1) limit of the nominal method, which is lower than the observed one.

Count model. Negative binomial counts with mean recovery x EPG / factor, fitted to the published mean and SD of ln(count + 1).

Herd limits without assumptions. For a count c, let q_c be the fraction of animals with a count of at least c and s_c the probability of such a count at the threshold EPG t. The probability rises with EPG, so for every distribution of EPG among the animals the fraction at or above t lies between (q_c - s_c)/(1 - s_c) and q_c/s_c. fraction_above uses several counts c (chosen from the design, not from the data), exact binomial intervals for their q_c with a Bonferroni split, and a linear programme over all distributions of EPG consistent with those intervals; the limits are the smallest and largest fraction at or above t. Uncertainty of recovery and k from the spiked samples is included through bootstrap percentiles (count_model_ci): a larger recovery rescales the EPG axis and lowers both limits, so the lower limit uses the upper end of the recovery range and the upper limit its lower end. Half of 1 - conf goes to the herd data, half to the parameters. Assumes one examination per animal, independent examinations and no false positives.

Aggregation model. A fraction of the animals is infected and their EPG follows a gamma distribution (shape and mean free); counts then follow the count model of the combination (within-sample variation by Gauss-Laguerre quadrature). Fitted by maximum likelihood; intervals for prevalence and for the fraction at or above t are profile-likelihood intervals, with the parameter uncertainty handled as above.

Survey size. Every animal at or above t is positive with probability at least s_1(t), taken at the least favourable end of the 95% parameter range, so n = ln(1 - conf) / ln(1 - fraction x s_1(t)) whatever the other animals carry.

Replicate planning. The CV of the mean of n independent counts is sqrt((1/mean + 1/k) / n). With --species the recovery and k of the count model are used. k describes variation between independently prepared samples, so the replicates are separate preparations, not re-readings of one chamber.

Validation

python validation/run_validation.py writes validation/REPORT.md and validation/detection_curves.png (needs pip install mcmaster-epg[validation]); python validation/run_herd_validation.py writes validation/HERD_REPORT.md (about an hour on two cores) and python validation/run_calibration_validation.py writes validation/CALIBRATION_REPORT.md (about five minutes); both use the available cores (SLURM_CPUS_PER_TASK on a cluster, otherwise up to 8). On a cluster, sbatch validation/helios.sbatch runs all three with every core of the job and SIM_SCALE times more simulated herds and studies (default 4 there; a few minutes on 192 cores), and VALIDATIONS="calibration herd" selects some of them. The calibration and herd reports in validation/ come from such a run with SIM_SCALE=4. pytest runs the tests. Main results (all 16 combinations of egg type, faeces and counting variant in the paper):

  • the published tables are internally consistent: Table 4 limits are reproduced from Table 3 in 16 of 16 combinations;
  • the two-parameter detection curve is not rejected in 16 of 16 combinations (parametric bootstrap of the deviance), and it predicts left-out spiking levels with a mean error of 6.8 percentage points, against 5.7 from binomial sampling error alone and 11.9 for the textbook Poisson model;
  • curves fitted to Ascaris suum in dog faeces predict the independent pig samples with errors of 2.9 to 9.4 percentage points;
  • the Poisson interval keeps its 95% coverage only if counts are Poisson; at the dispersion found for Toxocara canis (k = 4.4) its mean coverage falls to 74%, while the negative binomial interval keeps 95%.

Calibration (validation/CALIBRATION_REPORT.md; 2000 simulated spiking studies per row, true recovery 0.40 to 0.74, k from 1.5 to Poisson; Monte Carlo SE 0.5% at 95%):

  • with eight levels of 20 samples, the 95% intervals of recovery, k, LOD50 and LOD95 contain the truth in 94.4% to 98.0% of studies, and the 98.75% ranges used by the herd calculations in 98.3% to 99.5%;
  • with five levels of 10 samples, the 95% interval of recovery contains it in 93.8% to 95.4% and its 98.75% range in 98.5% to 98.6%; the other intervals stay at 94.3% or more;
  • LOD95 from the count model keeps 94.3% or more, while the detection curve fitted to positive results alone falls to 91.7%, which is why the count model gives the limits and the curve is only a check.

Herd results (validation/HERD_REPORT.md; simulated herds of 30 and 100 animals, 400 to 1200 herds per row, with recovery and k redrawn for every herd from a bootstrap of the spiking design):

  • limits without assumptions contain the true fraction in at least 99.7% of herds in every scenario, including the least favourable distributions; they are wide (mean width 0.38 to 1.00 with 100 animals), and 0 to 0.53 of that width remains even with unlimited animals, because a single McMaster count cannot place animals near the threshold on one side of it;
  • under the gamma aggregation model, when the model holds, the intervals are narrower (mean width 0.18 to 0.54 with 100 animals) with bias below 0.05; coverage is at least 0.97 with 100 animals but only 0.909 to 0.959 with 30 animals (lowest under strong aggregation, shape 0.5, and at 150 EPG in the moderately infected herd); when the model does not hold (a bimodal herd) the estimate is biased by up to 0.29 and coverage falls to 0, so compare it with the limits without assumptions;
  • prevalence of infection under the aggregation model: coverage 0.978 to 0.994 where the model holds, but the upper limit is 100% in 60% to 98% of those herds;
  • the mean EPG interval covers the truth in at least 98.3% of herds, with a median estimate within 10% of the truth;
  • planned survey sizes find a positive in at least 95.3% of least favourable herds (target 95%; Monte Carlo SE 0.1%).

A model limit equal to the published one is not a usable criterion: the published limit is read from 20 replicates on a grid of eight levels, and even an exactly true curve would match it in only about 9 of 16 combinations (simulation). The fitted curve matches it in 10 of 16 and is within one level in 16 of 16.

Limits

  • The built-in profiles come from one laboratory, one chamber type, three egg types and dog and pig faeces, and are fitted to the published summary tables; for other procedures calibrate from your own spiked samples or enter published parameters.
  • Detection limits above the highest spiking level (300 eggs/g for the built-in profiles) are extrapolations; the output marks them.
  • Calibration assumes that recovery does not depend on the level (tested) and that each spiked sample was prepared independently (not tested).
  • Herd results assume one examination per animal, independent examinations, no false positives, and animals whose egg loss resembles that of the spiked samples. Intervals of the aggregation model are somewhat too narrow with 30 animals (coverage 0.909 to 0.959 for nominal 0.95).

How to cite

Kochanowski M. mcmaster-epg, version 1.0.1. See CITATION.cff.

Kochanowski M, Dąbrowska J, Karamon J, Cencek T, Osiński Z. Analysis of the accuracy and precision of the McMaster method in detection of the eggs of Toxocara and Trichuris species (Nematoda) in dog faeces. Folia Parasitologica 2013; 60(3): 264-272. https://doi.org/10.14411/fp.2013.030

Licence

MIT

Metadata

Release files for mcmaster-epg 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcmaster-epg 1.0.1
File Size Uploaded Provenance Actions
mcmaster_epg-1.0.1.tar.gz 551.2 kB With provenance Details for mcmaster_epg-1.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcmaster-epg 1.0.1
File Interpreter ABI Platform Actions
mcmaster_epg-1.0.1-py3-none-any.whl Python 3 none any Details for mcmaster_epg-1.0.1-py3-none-any.whl

Total release size: 601.5 kB

Release files / mcmaster_epg-1.0.1.tar.gz

Download URL mcmaster_epg-1.0.1.tar.gz
Size 551.2 kB
Tags Source
SHA-256 checksum
How to use checksums
cff0e3df892614df361e837b6983cecf4fdd93b0a14c5fd580e7046193fd918a
BLAKE2b-256 checksum
How to use checksums
7c9e6a145667e2a6fc2fb486d6fca49d5d16bdf8a271d463bfc6961789d9267e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / mcmaster_epg-1.0.1-py3-none-any.whl

Download URL mcmaster_epg-1.0.1-py3-none-any.whl
Size 50.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ad650ffcd6ea54d94e9e4e05704491b141df7509bfaf769372d7e50c7e8eaf87
BLAKE2b-256 checksum
How to use checksums
32779f3dae9a670a52be51939ce771667569542cba00f86f28d3564cfa9ce15f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for mcmaster-epg 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mcmaster_epg-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page