loading...
running...
How to use
Pick a preset and watch the apiary. Every survey draws colonies by the chosen protocol, tests the chosen number of bees from each, and reports a corrected prevalence with two confidence intervals. Surveys repeat so you see how the estimates scatter around the hidden truth. Try: (1) Detect an early outbreak and raise the colonies sampled until the detection probability reaches the confidence level; (2) Convenience at the gate, where easy-to-reach colonies miss a far-end hotspot completely; (3) Many bees, few colonies versus Few bees, many colonies, where the naive interval claims much more certainty than it has; (4) lower the assay sensitivity and compare the raw and corrected rates.
Space pauses, R clears the tally. Click a colony to inspect its bee frame. Educational statistics only: no real apiary data and no advice about treating or managing a real colony.
The science
The hidden truth. The apiary has N colonies. Colony i has a within-colony prevalence qi (the fraction of its bees carrying the virus). The qi are drawn from a Beta distribution with mean π and intraclass correlation ρ, which controls how unequal the colonies are:
qi ~ Beta(a, b), a = π(1/ρ - 1), b = (1 - π)(1/ρ - 1), Var(q) = ρ π(1 - π)
The values are then placed on the yard map: with spatial clustering κ the most infected colonies sit near the hotspot position, otherwise they are scattered at random.
The assay. A tested bee reads positive with probability ri = (1 - Sp) + (Se + Sp - 1) qi, where Se is sensitivity and Sp specificity. A survey tests m bees in each of n colonies, so the positives in colony i are Binomial(m, ri).
Estimator. The raw rate a = positives / (n m) is corrected for assay error (Rogan-Gladen):
π̂ = (a - (1 - Sp)) / (Se + Sp - 1)
Under random colony selection it is unbiased for the mean of the qi. Its variance has a between-colony part with the finite-population factor (1 - n/N) and a within-colony part:
Var(π̂) = [ Sr2/n · (1 - n/N) + mean(r(1 - r)) / (n m) ] / (Se + Sp - 1)2
Design effect. Bees from the same colony are not independent. The effective number of independent bees is n m / deff with deff = 1 + (m - 1) ρ. A naive Wilson interval treats all n m bees as independent and is too narrow when ρ is large; the cluster-aware interval uses the spread of the colony proportions (Student t with n - 1 degrees of freedom, times (1 - n/N)), which is the honest one. Compare their coverage in the readout: at 95 % confidence a correct interval should contain the truth in about 95 % of the repeated surveys.
Detection. Here detection means at least one positive test result, so assay false positives (1 - Sp) count too. A colony pool shows no positive bee with probability zi = (1 - ri)m. For n colonies drawn without replacement the chance of no positive anywhere is the elementary symmetric polynomial en(z1..zN) / C(N, n), computed exactly by the recursion fj[k] = fj-1[k](j - k)/j + zj fj-1[k - 1] k/j. For a homogeneous population this collapses to zn and to the familiar rule n ≥ ln(1 - c) / ln(1 - r) (about 3/r for 95 %). The convenience design always tests the same colonies nearest the gate, so its detection and bias depend on where the virus sits; no amount of repetition fixes that.
Checks (run in the page). (1) the exact detection probability against 20,000 simulated random surveys; (2) the recursion against the closed form zn for identical colonies; (3) the standard error of the estimate from simulation against the two-stage formula above; (4) the mean corrected estimate against the true apiary prevalence. Checks run on a random-selection apiary built from your current settings.
Simplifications. Bees are tested individually and their results are independent given the colony; real surveillance often tests pooled homogenates and quantifies virus load. The Beta heterogeneity and the single hotspot are modelling choices, not field data. There is no time dynamics (spread, seasonality, mite pressure), colonies are equal size, and the confidence level is the nominal frequentist one. This is a teaching model for sampling design, not a diagnostic or management tool.