Planning rare-event studies¶
A study of a rare outcome is limited by the number of events or positives it observes, not by the number of people it enrolls or tests. This guide works through the planning calculations for a hypothetical vaccine against a rare infection, where evidence comes from several layers of a surveillance pyramid:
| Layer | What is counted | Typical design |
|---|---|---|
| Infection | Seroconversions in a followed cohort | Cohort with scheduled serology |
| Symptomatic disease | Confirmed febrile illness | Cohort with active fever surveillance |
| Medically attended disease | Test-positive presenters at facilities | Facility surveillance; test-negative design |
All numbers below are invented. Each layer has its own rate, ascertainment and test performance, so each endpoint needs its own sample size.
Event targets become person-time¶
An event-driven trial fixes the number of confirmed events first
(events_required) and then follows enough person-time to
observe them. Suppose 2% of the target population is infected each year and
15% of infections are symptomatic. Symptomatic disease is the primary endpoint
(efficacy 70% against a 30% margin); infection, measured by serology, is a key
secondary endpoint (efficacy 50% against 0).
from trade_study import events_required, person_time_for_events
hazard, symptomatic = 0.02, 0.15
disease_events = events_required(0.7, margin=0.3)
infection_events = events_required(0.5)
disease_time = person_time_for_events(
disease_events, hazard * symptomatic, efficacy=0.7, ascertainment=0.9
)
infection_time = person_time_for_events(
infection_events, hazard, efficacy=0.5, ascertainment=0.8
)
print(disease_events, round(disease_time), infection_events, round(infection_time))
The disease endpoint needs 78 events and about 44,000 person-years; the infection endpoint needs 99 events but only about 8,300 person-years, because most infections are not symptomatic. The infection endpoint is cheaper only if serology can separate infection from vaccination and the vaccine prevents infection as well as disease, and only if false seroconversions are controlled (below).
Surveillance that must find positives¶
When about 0.5% of presenters test positive, precision depends on the number
of positives. trials_for_positives gives the number to test for a stated
chance of observing at least that many, and expected_relative_half_width
the expected interval half-width relative to the true positivity, averaged
over the possible outcomes.
from trade_study import (
expected_relative_half_width,
trials_for_positives,
trials_for_relative_precision,
)
tested_for_20 = trials_for_positives(0.005, 20, assurance=0.9)
width_at_4000 = expected_relative_half_width(4000, 0.005)
tested_for_30_percent = trials_for_relative_precision(0.005, 0.3)
print(tested_for_20, round(width_at_4000, 2), tested_for_30_percent)
Testing 4,000 presenters gives an expected half-width of about 46% of the positivity; about 9,200 are needed for 30%. Splitting the same total across sites divides the positives, so per-site comparisons need more.
Rates from a cohort, and false conversions¶
A seroconversion cohort estimates an infection rate over person-time with the exact Garwood interval. At low rates, single serological calls produce false conversions that dilute efficacy toward zero; requiring two independent positive calls trades sensitivity for specificity.
from trade_study import observed_efficacy, rate_interval, repeated_test_accuracy
interval = rate_interval(18, 950.0)
single = observed_efficacy(0.5, 0.02, sensitivity=0.9, specificity=0.99)
se, sp = repeated_test_accuracy(0.9, 0.99, tests=2, rule="all")
confirmed = observed_efficacy(0.5, 0.02, sensitivity=se, specificity=sp)
print(round(interval.low, 4), round(interval.high, 4))
print(round(single.observed, 2), round(confirmed.observed, 2))
With a 2% risk and 99% specificity per call, about 42% of positive calls are false and the expected efficacy falls from 50% to about 32%; confirmation restores it to within a point of 50%, at the cost of 10% of true conversions. Use the observed efficacy, not the true one, when computing the event target.
Medically attended disease: a test-negative design¶
Severe or medically attended disease is usually too rare to power in a cohort. A facility-based test-negative design compares the odds of vaccination among test-positive cases and test-negative controls. The vaccinated share among controls drives the requirement.
from trade_study import tnd_cases_required, tnd_observed_efficacy
cases_half = tnd_cases_required(0.8, control_coverage=0.5, controls_per_case=4)
cases_fifth = tnd_cases_required(0.8, control_coverage=0.2, controls_per_case=4)
diluted = tnd_observed_efficacy(
0.8, 0.005, sensitivity=0.95, specificity=0.999, control_coverage=0.5
)
print(cases_half, cases_fifth, round(diluted, 2))
With half of presenters vaccinated, 29 test-positive cases give 90% power to show efficacy above zero when it is 80%; with a fifth vaccinated, 65 are needed. A test-negative design avoids following a cohort but not the case count: the vaccinated population must be large enough to produce those cases among presenters. At 0.5% positivity, 99.9% specificity already lowers the expected efficacy from 80% to about 71%.
Prevalence from an imperfect assay¶
corrected_prevalence applies the Rogan-Gladen correction and maps the exact
binomial interval through it, clipping at zero.
from trade_study import corrected_prevalence
baseline = corrected_prevalence(52, 1500, sensitivity=0.9, specificity=0.98)
print(round(baseline.apparent, 4), round(baseline.estimate, 4))
print(round(baseline.low, 4), round(baseline.high, 4))
An apparent prevalence of 3.5% corresponds to about 1.7% (0.7% to 2.9%) after correction: at this specificity, more than half of the positive results are false.
What the calculations assume¶
These are planning calculations with independent events, constant rates and
known test accuracy. Clustering by site or household, heterogeneity between
participants, uncertain sensitivity and specificity, and correlated test errors
all widen the true uncertainty. Use them to set the scale of a study, then
check the chosen design by simulation with run_grid,
power_curve and confusion_table.