Skip to content

Estimating the reproduction number from overdispersed counts ​

Introduction ​

Conjugate gamma–Poisson estimation estimates by window from two sums, of the counts and of the infection pressure. Its gamma posterior assumes that each count is Poisson given the earlier counts. Real counts usually vary more than that, for example through superspreading or clustered reporting. The gamma intervals are then too narrow, and they miss the true more often than they claim.

This page is for readers whose counts are overdispersed. It keeps the model, the windows and the two sums of the first page, and changes only the distribution of each count. It simulates one overdispersed outbreak and shows how far the gamma posterior falls short. It then gives two intervals that allow for the extra variation. One is an exact posterior when the dispersion is known. The other is a confidence interval that estimates the dispersion from the data []. The last section shows how often each interval contains the true value as the dispersion grows.

It assumes you have read Conjugate gamma–Poisson estimation.

Packages used ​

julia
using ComposableRecurrences
using ComposableRecurrences: Transform, pressure, window_sums
using Distributions: BetaPrime, Gamma, NegativeBinomial, Normal, cdf,
    mean, quantile, rate, shape
using Random, Statistics
using CairoMakie, AlgebraOfGraphics, DataFramesMeta

CairoMakie.activate!(type = "png", px_per_unit = 2)

Functions from the first page ​

These are the window, posterior and plotting functions of the first page, repeated so this page runs on its own.

julia
# Windows of `width` days that follow one another over `days`.
function consecutive(width, days)
    starts = first(days):width:(last(days) - width + 1)
    return (starts = starts, stops = starts .+ (width - 1))
end

# The sums of the counts `y` and of the multipliers `E` over each window.
function window_totals(y, E, w)
    return (
        cases = window_sums(y, w.starts, w.stops),
        pressure = window_sums(E, w.starts, w.stops),
    )
end

# The gamma posterior of each window, from a gamma prior and the totals.
function gamma_posterior(prior, totals)
    return Gamma.(
        shape(prior) .+ totals.cases,
        1 ./ (rate(prior) .+ totals.pressure)
    )
end

# The mean and central 95% interval of each posterior, one for each day.
function summarise(posterior, days; series = "Posterior")
    return DataFrame(
        day = collect(days), mean = mean.(posterior),
        lower = quantile.(posterior, 0.025),
        upper = quantile.(posterior, 0.975), series = series
    )
end

# A line and a band by day for each series, with `truth` dashed in black.
function plot_posterior(df, truth)
    order = sorter(unique(df.series))
    by = mapping(color = :series => order => "", col = :series => order)
    estimate = data(df) * by * (
        mapping(:day, :lower, :upper) * visual(Band, alpha = 0.3) +
            mapping(:day, :mean) * visual(Lines, linewidth = 2)
    )
    reference = data(truth) * mapping(:day, :R) *
        visual(Lines, color = :black, linestyle = :dash)
    axis = (; xlabel = "Day", ylabel = "Reproduction number")
    return draw(
        estimate + reference; axis, legend = (show = false,),
        figure = (size = (640, 300),)
    )
end

An overdispersed outbreak ​

Suppose that each unit of pressure causes a Poisson number of infections, whose rate is gamma distributed with mean and shape . Some infections then cause many more infections than others. The count on day is negative binomial,

with mean and variance  . The ratio of the variance to the mean is   . A smaller gives more overdispersed counts. As   the count tends to the Poisson count of the first page. With the whole generation interval on one lag this is the generation model of [], a branching process with negative binomial offspring.

As on the first page, each count is the quantile at a uniform draw . The size depends on , so the Transform modifier reads both and for each day.

julia
# A count with mean `v` and size `κ v / R`, drawn at the uniform `θ.u`.
function nb_count(κ)
    return function (v, θ)
        v > 0 || return 0.0
        count = NegativeBinomial(κ * v / θ.R, κ / (κ + θ.R))
        return float(quantile(count, θ.u))
    end
end
per_day(x::AbstractVector) = TimeVarying(x)
per_day(x::AbstractMatrix) = TimeVarying(PerStratum(x))

# A modifier that draws an overdispersed count from each value.
function nb_counts(κ, u, R)
    return Transform(nb_count(κ), (u = per_day(u), R = per_day(R)))
end

The generation interval, and the starting infections are those of the first page. is 1.6 on days 1 to 28, 0.8 on days 29 to 49 and 1.2 on days 50 to 70. The shape is  , so is 4.2 while  .

julia
gi = [0.05, 0.2, 0.3, 0.25, 0.12, 0.08]
L = length(gi)
T = 70
R = [t <= 28 ? 1.6 : t <= 49 ? 0.8 : 1.2 for t in 1:T]
seed = fill(10.0, L)
κ = 0.5
renewal = Recurrence(
    gi; modifiers = (nb_counts(κ, rand(Xoshiro(1), T), R),)
)
incidence = renewal(R; history = seed)
truth = DataFrame(day = 1:T, R = R)

@chain DataFrame(day = 1:T, incidence = incidence) begin
    data(_) * mapping(:day, :incidence) * visual(Scatter, color = :black)
    draw(
        _; axis = (xlabel = "Day", ylabel = "Incidence"),
        figure = (size = (640, 300),)
    )
end

The counts follow the three levels of as on the first page, but jump more from day to day.

A posterior for known dispersion ​

With known, the posterior of over a window is a scaled beta prime distribution. It uses the same two window totals as the gamma posterior,

where and are the shape and rate of the gamma prior on the first page. It tends to the gamma posterior as  . Its variance is that of the gamma posterior multiplied by approximately  , which is .

Why the posterior is beta prime

The probability    does not depend on , so the likelihood of a window is

the kernel of a beta density in . A beta prior on is a beta prime prior on   . The prior   therefore gives the posterior above. [] give this posterior for their model, as a beta distribution for  . The derivation shows that it holds for any known generation interval when the size is proportional to the pressure.

julia
# The posterior of each window for counts whose size is `κ` times the
# pressure, from the totals and the parameters of the limiting gamma prior.
function beta_prime_posterior(prior, totals, κ)
    return κ .* BetaPrime.(
        shape(prior) .+ totals.cases,
        κ .* (rate(prior) .+ totals.pressure)
    )
end

The windows are the ten weeks of the run, with the prior of the first page. The figure sets the gamma posterior, which treats the counts as Poisson, against the beta prime posterior.

julia
prior = Gamma(1, 5)
weeks = consecutive(7, 1:T)
week_of_day = repeat(1:length(weeks.starts); inner = 7)
Λ = pressure(renewal, incidence; history = seed)
totals = window_totals(incidence, Λ, weeks)
as_poisson = gamma_posterior(prior, totals)
known_κ = beta_prime_posterior(prior, totals, κ)
fits = vcat(
    summarise(as_poisson[week_of_day], 1:T; series = "Gamma (Poisson)"),
    summarise(known_κ[week_of_day], 1:T; series = "Beta prime")
)
plot_posterior(fits, truth)

The line is the posterior mean, the band the central 95% interval and the dashed line the simulating . The two posteriors have nearly the same mean. The gamma band is narrower, by about half while is 1.6, and it misses the simulating value in three of the first four weeks. The beta prime band allows for the extra variation in the counts.

An interval for unknown dispersion ​

The dispersion is rarely known. With unknown there is no closed-form posterior. [] instead fit quasi-Poisson and negative binomial models by maximum likelihood, and their paper covers those fits in full. This section uses their quasi-Poisson interval, which needs no choice of count distribution.

The quasi-Poisson model keeps the mean   and sets the variance to , with unknown. The estimate is the ratio of the two window totals, as for the Poisson model. The Poisson standard error is widened by , the Pearson estimate of the dispersion from the days of the window [],

where is the number of days in the window. The interval is  . It is a confidence interval, not a posterior. Expanding the square writes the Pearson sum with one more window sum, of .

julia
# The quasi-Poisson estimate of each window and its 95% interval.
function quasi_poisson(y, E, w)
    totals = window_totals(y, E, w)
    estimate = totals.cases ./ totals.pressure
    ratio = window_sums(
        ifelse.(E .> 0, y .^ 2 ./ E, 0.0), w.starts, w.stops
    )
    n = (w.stops .- w.starts .+ 1)'
    ϕ = (ratio ./ estimate .- totals.cases) ./ (n .- 1)
    se = estimate .* sqrt.(ϕ ./ totals.cases)
    return (;
        estimate, lower = estimate .- 1.96 .* se,
        upper = estimate .+ 1.96 .* se,
    )
end

The figure sets the quasi-Poisson interval of each week against the beta prime posterior.

julia
quasi = quasi_poisson(incidence, Λ, weeks)
quasi_fit = DataFrame(
    day = 1:T, mean = vec(quasi.estimate)[week_of_day],
    lower = vec(quasi.lower)[week_of_day],
    upper = vec(quasi.upper)[week_of_day], series = "Quasi-Poisson"
)
beta_prime_fit = summarise(known_κ[week_of_day], 1:T; series = "Beta prime")
plot_posterior(vcat(quasi_fit, beta_prime_fit), truth)

The quasi-Poisson interval has about the width of the beta prime interval, without knowing . Its width varies more from week to week, since each comes from only seven days.

How often each interval contains the true value ​

One outbreak shows the widths, not how often each interval is right. The calibration check of the first page answers this by simulation. Here it is repeated for several values of . Each value has 2000 outbreaks of 21 days with   from 20 infections a day, held as strata of one recurrence. Each outbreak has one window, days 8 to 21.

[] show that a Poisson interval understates the standard error by the factor . A nominal 95% interval then contains the true value with probability

where is the standard normal distribution function.

julia
# The share of intervals from `lower` to `upper` that contain `value`.
coverage(lower, upper, value) = mean(lower .<= value .<= upper)

# The coverage of each interval for 2000 outbreaks with shape `κ`.
function coverage_at(κ; R = 1.5, n = 2000, days = 21)
    u = rand(Xoshiro(round(Int, 100κ)), n, days)
    count = nb_counts(κ, u, fill(R, n, days))
    outbreaks = Recurrence(gi; modifiers = (count,))
    seeds = fill(20.0, n, L)
    y = outbreaks(fill(R, n, days); history = seeds)
    Λ = pressure(outbreaks, y; history = seeds)
    window = (starts = [8], stops = [days])
    totals = window_totals(y, Λ, window)
    gamma = gamma_posterior(prior, totals)
    beta_prime = beta_prime_posterior(prior, totals, κ)
    quasi = quasi_poisson(y, Λ, window)
    interval(d, p) = quantile.(d, p)
    return DataFrame(
        κ = κ,
        interval = ["Gamma (Poisson)", "Beta prime", "Quasi-Poisson"],
        coverage = [
            coverage(interval(gamma, 0.025), interval(gamma, 0.975), R),
            coverage(
                interval(beta_prime, 0.025), interval(beta_prime, 0.975), R
            ),
            coverage(quasi.lower, quasi.upper, R),
        ]
    )
end

shapes = [0.25, 0.5, 1, 2, 5, 20]
coverages = reduce(vcat, coverage_at.(shapes))
predicted = DataFrame(κ = exp.(range(log(0.2), log(25); length = 100)))
ϕ = 1 .+ 1.5 ./ predicted.κ
predicted.coverage = 1 .- 2 .* cdf.(Normal(), -1.96 ./ sqrt.(ϕ))

draw(
    data(coverages) *
        mapping(:κ, :coverage, color = :interval => "") *
        visual(ScatterLines, markersize = 10) +
        data(predicted) * mapping(:κ, :coverage) *
        visual(Lines, color = :grey, linestyle = :dot) +
        mapping([0.95]) * visual(HLines, color = :black, linestyle = :dash);
    axis = (
        xlabel = "Shape κ (smaller is more overdispersed)",
        ylabel = "Coverage of the 95% interval", xscale = log10,
        xticks = (shapes, ["0.25", "0.5", "1", "2", "5", "20"]),
    ),
    figure = (size = (640, 320),)
)

The dashed line is the nominal 0.95 and the dotted line the coverage predicted for the Poisson interval. The gamma posterior falls well short as the counts become more overdispersed, close to the prediction. The beta prime posterior, which knows , stays at 0.95. The quasi-Poisson interval stays close to 0.95 without knowing . It falls a little short because comes from only 14 days.

Other count models ​

Other negative binomial models, with the size proportional to the mean or constant, have no beta prime posterior. [] fit them by maximum likelihood and compare their intervals with the quasi-Poisson one. Models that need no closed form, such as a negative binomial count with unknown dispersion, can be fitted with particle filtering or MCMC.

References ​

  1. B. Němcová, I. H. Goldstein, J. Sebastian, V. M. Minin and J. Bracher. Unjustified Poisson assumptions lead to overconfident estimates of the effective reproductive number. Epidemiology and Infection 154, e79 (2026).

  2. K. D. Johnson, M. Beiglböck, M. Eder, A. Grass, J. Hermisson, G. Pammer, J. Polechová, D. Toneian and B. Wölfl. Disease momentum: Estimating the reproduction number in the presence of superspreading. Infectious Disease Modelling 6, 706–728 (2021).

  3. P. McCullagh and J. A. Nelder. Generalized Linear Models. 2 Edition (Springer US, 1989).