Skip to content

API reference

epidemic-dates

Simulate an epidemic with reporting delays and missing onset dates, impute the missing onsets four ways and compare with the truth. See the Home page for an overview and quick start.

Warning. This code was generated by an LLM. Sam Abbott has only checked the interactive page. This module has not been reviewed by a person.

epidemic-dates.D : number

Maximum onset-to-report delay in days. Delay pmfs have D + 1 entries (delays 0 to D). Also the length of the burn-in before day 0.

Kind: static constant of epidemic-dates

epidemic-dates.KNOTS : ReadonlyArray.<number>

Knot days for growth rate and ascertainment curves: 0, 15, ..., 360 (25 knots). Curves are linear between knots and flat beyond the last.

Kind: static constant of epidemic-dates

epidemic-dates.R_MIN : number

Lower limit of the growth rate (per day) used by the page for drawing and axes. Not enforced by this module.

Kind: static constant of epidemic-dates

epidemic-dates.R_MAX : number

Upper limit of the growth rate (per day) used by the page. Not enforced by this module.

Kind: static constant of epidemic-dates

epidemic-dates.DEFAULTS : ScenarioParams

Default scenario parameters: 175 days shown, growth as in the baseline preset, a constant 6.6-day mean delay and 15% of onsets missing, viewed in real time with a nowcast. The baseline preset (the first of PRESETS) adds time-varying delay, missingness and ascertainment. Frozen: copy it before changing a field.

Kind: static constant of epidemic-dates

epidemic-dates.PRESETS : ReadonlyArray.<Preset>

The scenarios on the page, in display order. The first is the baseline. Frozen: copy a preset's set before changing it.

Kind: static constant of epidemic-dates

epidemic-dates.METHODS : ReadonlyArray.<Method>

Imputation methods, by key:

  • backsampling: draw a delay from the pooled empirical delays of cases with both dates and subtract it from the report day.
  • mean: subtract the rounded mean of those delays.
  • fwd: draw from the forward (onset-weighted) delay. In simulation this is the true delay averaged over onsets, standing in for a delay estimated with a truncation adjustment.
  • gen: EM back-projection of missing-onset cases (see emImpute).

Kind: static constant of epidemic-dates

epidemic-dates.GI : Readonly.<{mean: number, sd: number}>

Gamma generation interval used for Rt, in days. Ebola-like mean 15 days and SD 9.

Kind: static constant of epidemic-dates

epidemic-dates.DELAY_SHRINKAGE : number

Default strength of the shrinkage of each period's EM delay towards the previous period's delay, in expected onsets. See imputeLinelist.

Kind: static constant of epidemic-dates

epidemic-dates.QUANTILES : ReadonlyArray.<number>

Default quantile levels for nowcastLinelist: the median and the 50%, 80% and 95% intervals.

Kind: static constant of epidemic-dates

epidemic-dates.NOWCAST_METHODS : ReadonlyArray.<string>

Imputation methods nowcastLinelist accepts. gen (EM back-projection) is the default.

Kind: static constant of epidemic-dates

epidemic-dates.curveAt(vals, t) ⇒ number

Value of a knot curve at day t. Linear between knots, flat before the first and after the last. Finds the knot interval by search, so it does not depend on the spacing of KNOTS.

Kind: static method of epidemic-dates
Returns: number - Interpolated value.

Param Type Description
vals ArrayLike.<number> Values at each knot (same length as KNOTS).
t number Day.

epidemic-dates.knotsFrom(pts) ⇒ Array.<number>

Knot values from a few anchor points. Linear between anchors, flat outside them, rounded to 4 decimal places.

Kind: static method of epidemic-dates
Returns: Array.<number> - One value per entry of KNOTS.

Param Type Description
pts Array.<Array.<number>> [day, value] pairs, sorted by day.

Example

knotsFrom([[0, 0.05], [60, 0.05], [120, -0.01]]);

epidemic-dates.delayPmf(mu, cv) ⇒ Float64Array

Daily onset-to-report delay pmf, double interval censored (primarycensored form). The primary event is uniform within its day and the secondary event is censored to its day, so P(d) = G(d + 1) − 2 G(d) + G(d − 1) with G(x) = x F(x; k, θ) − k θ F(x; k + 1, θ), the integral of the Gamma CDF F from 0 to x. Shape k = 1 / cv², scale θ = μ cv². Truncated at D and renormalised, so its mean is close to mu.

Kind: static method of epidemic-dates
Returns: Float64Array - Probabilities for delays 0..D. A new array on each call.

Param Type Description
mu number Mean delay of the underlying Gamma (days).
cv number Coefficient of variation of the Gamma.

epidemic-dates.wrongSideOf1(a, b) ⇒ boolean

Whether two growth rates are on opposite sides of 0 (Rt on opposite sides of 1). Ignored when both are within 0.0005/day of 0.

Kind: static method of epidemic-dates

Param Type Description
a number Growth rate per day.
b number Growth rate per day.

epidemic-dates.rToR(r) ⇒ number

Rt from a growth rate with the Gamma generation interval GI (Wallinga and Lipsitch): R = (1 + r θ_g)^k_g, with shape k_g = (mean / sd)² and scale θ_g = sd² / mean. The base is floored at 1e-6.

Kind: static method of epidemic-dates
Returns: number - Rt, or null if r is null.

Param Type Description
r number Growth rate per day.

epidemic-dates.clamp(x, a, b) ⇒ number

Restrict x to the interval [a, b].

Kind: static method of epidemic-dates

Param Type Description
x number Value.
a number Lower bound.
b number Upper bound.

epidemic-dates.pmfMean(f) ⇒ number

Mean of a pmf indexed by delay in days.

Kind: static method of epidemic-dates
Returns: number - sum(d * f[d]). Not renormalised.

Param Type Description
f ArrayLike.<number> Probabilities for delays 0, 1, ....

epidemic-dates.makeRng(seed, [stream]) ⇒ Rng

A seeded uniform generator (mulberry32). The same seed and stream always give the same sequence.

Kind: static method of epidemic-dates
Returns: Rng - Function returning uniforms on [0, 1).

Param Type Default Description
seed number Integer seed.
[stream] number 0 Integer stream number, so one seed can give several independent sequences.

epidemic-dates.scenario(p) ⇒ Scenario

Build a scenario: growth rate, expected onsets, delays and missingness. Onsets grow as exp(cumsum(r)) from O0 on day 0, after a burn-in of D days at the first knot growth rate, and are scaled by ascertainment.

Kind: static method of epidemic-dates

Param Type Description
p ScenarioParams Full parameter set (merge with DEFAULTS first). The mean delay comes from muKnots if set, else linear from mu0 to mu1. The fraction missing comes from piKnots if set, else linear from pi0 to pi1.

epidemic-dates.expectedData(sc) ⇒ ExpectedData

Expected observed data for a scenario, counting only cases reported by the cut-off.

Kind: static method of epidemic-dates

Param Type Description
sc Scenario Scenario.

epidemic-dates.normalise(a) ⇒ Float64Array

Scale an array to sum to 1.

Kind: static method of epidemic-dates
Returns: Float64Array - Normalised copy, all zeros if a sums to 0.

Param Type Description
a ArrayLike.<number> Non-negative weights.

epidemic-dates.convImpute(comp, miss, g, S) ⇒ Float64Array

Allocate missing-onset cases back in time with a single delay pmf: the expected result of drawing each delay from g (backsampling and fwd).

A case reported on day t gets onset s with P(s | t) = g(t − s). For backsampling, g is the pooled empirical delay, g(d) ∝ Σ_{s ≤ T − d} C(s) fₛ(d) (1 − π(s + d, d)). Under constant growth r this is g(d) ∝ f(d) e^(−r d), the correct backward delay. For fwd, g = f̄, the onset-weighted forward delay. The correct posterior is P(s | t) ∝ C(s) fₛ(t − s) π(t, t − s).

Kind: static method of epidemic-dates
Returns: Float64Array - comp plus the allocated cases, by onset day.

Param Type Description
comp ArrayLike.<number> Complete cases by onset day.
miss ArrayLike.<number> Missing-onset cases by report day.
g ArrayLike.<number> Delay pmf. Must have at least D + 1 entries.
S number Length of the output. Mass before day 0 or at day S or later is dropped.

epidemic-dates.shiftImpute(comp, miss, m, S) ⇒ Float64Array

Move each missing-onset case back by a fixed delay (mean): s = t − m, with m = round(Σ_d d g(d)) for the pooled empirical delay g.

Kind: static method of epidemic-dates
Returns: Float64Array - comp plus the shifted cases, by onset day.

Param Type Description
comp ArrayLike.<number> Complete cases by onset day.
miss ArrayLike.<number> Missing-onset cases by report day.
m number Delay in whole days.
S number Length of the output.

epidemic-dates.emImpute(comp, miss, sc, start, [iterations], [onIter]) ⇒ Float64Array

EM back-projection of missing-onset cases (gen), 80 iterations.

Missing cases reported on day t are shared over onset days s with P(s | t) ∝ λ(s) fₛ(t − s). Then λ(s) = (n_complete(s) + n_alloc(s)) / Fₛ(T − s), which adjusts for right truncation at the cut-off T. The two steps are iterated towards a fixed point.

Assumes onsets are missing at random given report day, so cases with a missing onset have the same delay distribution as all cases reported that day. Then the fixed point matches the correct posterior P(s | t) ∝ C(s) fₛ(t − s) π(t, t − s). Uses the true, time-varying delay from the scenario, so in simulation it has oracle knowledge of the delay.

A proper generative model would jointly estimate a time-varying delay, smooth λ (for example with a renewal process) and could model ascertainment, as epinowcast does. Here the delay is given, which is acceptable for this demonstration.

Kind: static method of epidemic-dates
Returns: Float64Array - comp plus the allocated cases, by onset day. Not truncation adjusted.

Param Type Default Description
comp ArrayLike.<number> Complete cases by onset day.
miss ArrayLike.<number> Missing-onset cases by report day.
sc Scenario Scenario, for f, F, S, T.
start ArrayLike.<number> Starting onset curve, for example the backsampling result.
[iterations] number 80 Number of EM iterations.
[onIter] EmCallback Called after each iteration. Used by the page to show the iterations.

epidemic-dates.runMethods(sc, comp, miss, empCounts) ⇒ MethodResults

Apply all four methods.

Kind: static method of epidemic-dates

Param Type Description
sc Scenario Scenario.
comp ArrayLike.<number> Complete cases by onset day.
miss ArrayLike.<number> Missing-onset cases by report day.
empCounts ArrayLike.<number> Delays of complete cases.

epidemic-dates.weekly(daily, W, off) ⇒ Float64Array

Sum daily counts into weeks.

Kind: static method of epidemic-dates
Returns: Float64Array - Weekly totals.

Param Type Description
daily ArrayLike.<number> Daily counts.
W number Number of weeks.
off number Index of the first day of week 0 (sc.B for scenario arrays). Days beyond the array count as 0.

epidemic-dates.growth(wk, [off]) ⇒ Array.<?number>

Weekly growth rate per day. For week w this is (log x[w + 1] - log x[w - 1]) / 14, with a one-sided difference between adjacent weeks in the first and last weeks.

Kind: static method of epidemic-dates
Returns: Array.<?number> - Growth rate per week, null where not defined.

Param Type Default Description
wk ArrayLike.<number> Weekly counts.
[off] number 0 Added before taking logs to guard against log(0) for stochastic counts. 0 for expected values.

epidemic-dates.stochastic(sc, W, reps, [nowcast], [seed]) ⇒ StochasticResult

Poisson replicates of a scenario. Each replicate draws complete and missing cases for every (onset, delay) cell, then imputes. backsampling and fwd draw delays multinomially. mean and gen are as in expectation. Draws come from a generator seeded with seed, so the same inputs give the same bands.

Weeks are left out of a band when fewer than max(3, reps / 3) replicates give a value. Relative errors need at least 5 true cases in the week. In real time the mean shift has no value in weeks that include days after T − m (see maskWeeks).

Kind: static method of epidemic-dates

Param Type Default Description
sc Scenario Scenario.
W number Number of weeks.
reps number Number of replicates.
[nowcast] boolean false Correct each method for right truncation and compare with all onsets that will eventually be reported, as in comparisonSeries.
[seed] number sc.seed Seed for the replicates. Defaults to the scenario seed, drawn on a separate stream from the growth rate noise.

epidemic-dates.metrics(tw, mw, gT, gM, ok, W, retro) ⇒ Metrics

Error metrics for one method. Growth rate, Rt, turning point and peak metrics use only complete weeks (ok), so truncation of the target is not mistaken for a change in the epidemic. Growth and Rt metrics also need at least 10 true cases in the week. Weeks where mw is not finite (NaN, for example from maskWeeks) have no value and are left out of every metric.

Kind: static method of epidemic-dates

Param Type Description
tw ArrayLike.<number> True weekly onsets.
mw ArrayLike.<number> Imputed weekly onsets. NaN where the method has no value.
gT Array.<?number> True weekly growth rates.
gM Array.<?number> Imputed weekly growth rates.
ok Array.<boolean> Complete weeks, from completeWeeks.
W number Number of weeks.
retro boolean Whether the view is retrospective.

epidemic-dates.completeWeeks(sc, W, [threshold]) ⇒ Array.<boolean>

Onset weeks at least 80% reported by the cut-off, in expectation.

Kind: static method of epidemic-dates
Returns: Array.<boolean> - One flag per week. Weeks with no onsets count as complete.

Param Type Default Description
sc Scenario Scenario.
W number Number of weeks.
[threshold] number 0.8 Smallest expected fraction reported for a week to count as complete.

epidemic-dates.correctTruncation(daily, sc, [minCover]) ⇒ Float64Array

Correct daily onset counts for right truncation by dividing by the expected fraction of each day's cases reported by the cut-off, F_s(T − s), using the true delay. Days with less than minCover reported are set to 0.

Kind: static method of epidemic-dates
Returns: Float64Array - Corrected daily counts.

Param Type Default Description
daily ArrayLike.<number> Daily onset counts, internal day index.
sc Scenario Scenario.
[minCover] number 0.05 Smallest fraction reported to correct.

epidemic-dates.maskWeeks(wk, sc, lastDay) ⇒ Float64Array

Set weeks that include any display day after lastDay to NaN, so they have no value. Used for the mean shift in real time: it moves every missing case back by m days, so it cannot place any case on an onset day later than T − m. With a fixed shift those days would be left out in practice, so they are not compared.

Kind: static method of epidemic-dates
Returns: Float64Array - A copy, with NaN in the masked weeks.

Param Type Description
wk ArrayLike.<number> Weekly values, week 0 starting on display day sc.wk0.
sc Pick.<module:epidemic-dates.Scenario, "wk0"> Scenario.
lastDay number Last display day with a value. Null or undefined to keep every week.

epidemic-dates.comparisonSeries(p, sc, ex, R) ⇒ ComparisonSeries

The daily series a method is compared on. Without a nowcast, the truth is the onsets of cases reported by the cut-off and each method's imputation is used as is. With p.nowcast in real time, every method is corrected for right truncation with the true delay (correctTruncation) and compared with all onsets that will eventually be reported. In real time the mean shift has no value after day Td − m (lastDay).

Kind: static method of epidemic-dates
Returns: ComparisonSeries - Daily series on the internal day index.

Param Type Description
p Pick.<module:epidemic-dates.ScenarioParams, ("nowcast"|"retro")> Scenario parameters.
sc Scenario Scenario.
ex ExpectedData Output of expectedData.
R MethodResults Output of runMethods.

epidemic-dates.run([params]) ⇒ RunResult

Run one scenario end to end, in expectation. Only whole weeks within days and the cut-off are returned. In real time the mean shift has no value in weeks that include days after T − m; these weeks are null and left out of its metrics.

Kind: static method of epidemic-dates

Param Type Default Description
[params] Partial.<ScenarioParams> {} Any subset of DEFAULTS.

Example

const EpidemicDates = require("./epidemic-dates.js");
const res = EpidemicDates.run({
  knots: EpidemicDates.knotsFrom([[0, 0.05], [60, 0.05], [120, -0.01]]),
  mu0: 8, mu1: 8, pi0: 0.4, pi1: 0.4
});
res.metrics.backsampling.maxRel; // largest weekly relative error, back-sampling method
Example
// a preset, in real time
const p = EpidemicDates.PRESETS[0].set;
EpidemicDates.run({ ...p, retro: false, cutoff: 120 }).rt.gen;

epidemic-dates.delayPeriods(T, [delayPeriod]) ⇒ Array.<number>

Split onset days 0..T into periods of delayPeriod days that end on the cut-off, so the latest period is always full length. The first period holds the days left over and can be shorter.

Kind: static method of epidemic-dates
Returns: Array.<number> - Period index (0, 1, ...) of each onset day.
Throws:

  • Error If delayPeriod is not a whole number of at least 1.
Param Type Default Description
T number Cut-off, a non-negative whole number.
[delayPeriod] number Period length in days, a whole number of at least 1. Null gives one period.

Example

delayPeriods(9, 4); // [0, 0, 1, 1, 1, 1, 2, 2, 2, 2]

epidemic-dates.imputeLinelist(input) ⇒ LinelistResult

Impute missing onsets in a real line list with all four methods.

Methods are as on the overview page, with T = cutoff. backsampling uses P(s | t) = g(t − s) for the pooled empirical delay g, mean uses s = t − round(Σ_d d g(d)) and fwd uses P(s | t) = f(t − s) for the given delay.

gen is EM back-projection: P(s | t) ∝ λ(s) fₛ(t − s) and λ(s) = (n_complete(s) + n_alloc(s)) / Fₛ(T − s). With delay it holds that delay fixed, static or one pmf per onset day. Without it, it estimates one static delay, allowing for right truncation: f(d) ∝ n(d) / Σ_{s ≤ T − d} λ(s), where n(d) counts complete and allocated cases with delay d. With delayPeriod it estimates one delay per period k instead, shrunk towards the previous period's delay h_k (the pooled f for the first period): f_k(d) ∝ (N_k(d) + κ h_k(d)) / (E_k(d) + κ), with N_k(d) the cases with onset in period k and delay d, E_k(d) = Σ_{s ∈ k, s ≤ T − d} λ(s) and κ = delayShrinkage. It assumes onsets are missing at random given report day and that the delay is constant within each period.

With a delay matrix, fwd uses P(s | t) ∝ fₛ(t − s) over onset days 0..t.

A proper generative model would jointly estimate a smoothly time-varying delay, smooth λ (for example with a renewal process) and could model ascertainment, as epinowcast does.

Kind: static method of epidemic-dates
Throws:

  • Error If onset and report differ in length, delay is not a valid pmf or matrix of pmfs, both delay and delayPeriod are given, or delayPeriod or delayShrinkage is out of range.
Param Type Description
input LinelistInput Line list and options.

Example

const { imputeLinelist } = require("./epidemic-dates.js");
const res = imputeLinelist({
  onset: [0, 1, null, 3, null, 4],
  report: [3, 5, 6, 8, 9, 10],
  cutoff: 10
});
res.imputed.backsampling; // daily onsets, back-sampling method
res.imputed.gen; // daily onsets, EM back-projection
res.generativeDelay; // estimated delay pmf

epidemic-dates.nowcastLinelist(input) ⇒ NowcastResult

Nowcast onsets from a line list, with uncertainty. Matches nowcast_linelist in the Python package, except that method em is gen and forward is fwd here, and random draws differ.

1. Impute. Complete cases keep their onset. Missing onsets are imputed by method: gen (default), EM back-projection with P(s | t) ∝ λ(s) f(t − s); backsampling, P(s | t) = g(t − s) with g the pooled empirical delay; mean, s = t − round(Σ_d d g(d)); fwd, P(s | t) = f(t − s). f is delay if given, used as is: one pmf, or one per onset day so fₛ changes over time. Otherwise it is estimated by EM, allowing for right truncation: one static delay, or with delayPeriod one per period, shrunk towards the previous period's. When fₛ changes over time, fwd uses P(s | t) ∝ fₛ(t − s) over onset days 0..t. This gives n̂(s) = n_c(s) + n_i(s), onsets of cases reported by T.

2. Correct for right truncation. The point nowcast is Ĉ(s) = n̂(s) / Fₛ(min(T − s, D)), with Fₛ the CDF of fₛ. Days with Fₛ(T − s) < minReported get no estimate (NaN).

3. Sample. Each sample, with a generator seeded by seed:

  • if bootstrap, resamples the complete cases with replacement, recomputes g, and refits EM to them and the missing cases, warm-started from the point fit for max(10, floor(iterations / 5)) iterations, giving f_b and λ_b (one delay per period with delayPeriod; with a given delay, only λ_b is refitted);
  • draws the missing onsets: backsampling and fwd as a multinomial over delays with g or f_b, gen as a multinomial over onset days with P(s | t) ∝ λ_b(s) f_b(t − s), and mean by a fixed shift of the rounded mean of g; with the complete cases this gives n_b(s);
  • draws the cases not yet reported, U(s) ~ NegBin(n_b(s), F_b(T − s)) (failures before n_b(s) successes, mean n_b(s)(1 − F_b)/F_b), the posterior for the total under a prior proportional to 1 / C(s), and returns n_b(s) + U(s).

Weekly samples sum the daily samples over full weeks ending on the cut-off. A week with any day without an estimate has none. Quantiles use linear interpolation between order statistics.

Captured: the draw of missing onsets given the delay and onset curve; the binomial reporting of recent onsets given the delay; with bootstrap, sampling uncertainty in the delay (and in the onset curve used by gen). Not captured: a delay that changes over time but is estimated as static, or that changes within a period; onsets missing other than at random given report day; dependence between cases, uncertainty in a given delay, and noise in the onset process itself. Days with no reported onsets get 0 in every sample.

Cases are dropped as by imputeLinelist.

Kind: static method of epidemic-dates
Throws:

  • Error If onset and report differ in length, there is no valid report day or complete case, method is unknown, delay is not a valid pmf or matrix of pmfs, both delay and delayPeriod are given, or nSamples, quantiles, minReported, iterations, maxDelay, seed, delayPeriod or delayShrinkage are out of range.
Param Type Description
input NowcastInput Line list and options.

Example

const { nowcastLinelist } = require("./epidemic-dates.js");
const res = nowcastLinelist({
  onset: [0, 1, null, 3, 4, null, 6, 8, null, 9],
  report: [2, 4, 5, 6, 7, 8, 9, 10, 11, 12],
  nSamples: 200,
  origin: "2026-05-08"
});
res.point; // point nowcast by onset day
res.weeklyQuantiles; // [{ week_start, target_end_date, quantile, value }]

epidemic-dates.ScenarioParams : Object

Scenario parameters. Any subset can be passed to run; missing fields come from DEFAULTS. Days are display days, with the first simulated onset day at 0.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
days number Number of onset days shown (N). Weeks run over days 0 to days - 1.
O0 number Expected onsets on day 0 before ascertainment. Earlier days come from a burn-in of D days at the first knot growth rate.
knots Array.<number> Growth rate per day at each KNOTS day.
rwSd number SD of daily AR(1) noise (coefficient 0.95) added to the growth rate from day 0. 0 for none.
seed number Seed for the growth rate noise. Also the default seed for stochastic replicates.
mu0 number Mean onset-to-report delay (days) for onsets on day 0. Ignored when muKnots is set.
mu1 number Mean delay for onsets on day days - 1. Linear in onset day between, flat outside. Ignored when muKnots is set.
muKnots Array.<number> Mean delay (days) by onset day at each KNOTS day, read with curveAt. Null to use mu0 and mu1.
cv number Coefficient of variation of the Gamma delay.
pi0 number Probability that an onset is missing for cases reported on day 0. Ignored when piKnots is set.
pi1 number Probability that an onset is missing for cases reported on day days - 1. Linear in report day between. Ignored when piKnots is set.
piKnots Array.<number> Probability that an onset is missing, by report day, at each KNOTS day. Null to use pi0 and pi1. Either way capped to [0, 0.999].
beta number Dependence of missingness on delay d: logit(p) = logit(base) + beta * (d - μ) / μ, where μ is the mean delay for the case's onset day. 0 means missing at random given report day.
asc Array.<number> Ascertainment multiplier at each KNOTS day, applied to onsets.
retro boolean If true, use all cases eventually reported (cut-off at days - 1 + D). If false, cut the data at cutoff.
cutoff number Report day of the data cut when retro is false. Capped at days - 1. Null for the last day shown.
nowcast boolean In real time, correct every method for right truncation with the true delay and compare with all onsets that will eventually be reported.
stoch boolean Show stochastic replicates. Used by the page only; run ignores it.
reps number Number of stochastic replicates. Used by the page, passed to stochastic.
ended boolean With retro, set onsets after day days - 1 to zero so the epidemic ends at the horizon.

epidemic-dates.Preset : Object

A named scenario shown as a button on the page.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
name string Short label.
note string One or two sentences describing the scenario.
set Partial.<ScenarioParams> Parameters that differ from DEFAULTS.

epidemic-dates.MethodKey : "backsampling" | "mean" | "fwd" | "gen"

Key of an imputation method.

Kind: static typedef of epidemic-dates

epidemic-dates.Method : Object

An imputation method.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
key MethodKey Short key used in results.
name string Label used on the page.

epidemic-dates.Rng ⇒ number

A uniform random number generator.

Kind: static typedef of epidemic-dates
Returns: number - A draw on [0, 1).

epidemic-dates.MissingProb ⇒ number

Probability that an onset is missing.

Kind: static typedef of epidemic-dates

Param Type Description
i number Internal report day.
d number Delay in days.

epidemic-dates.Scenario : Object

A simulated scenario in expectation. Arrays are indexed by internal day i = display day + B.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
N number Displayed onset days (params.days).
B number Burn-in length, equal to D.
T number Cut-off as an internal day (Td + B).
Td number Cut-off as a display day.
S number Number of internal days (T + 1).
r Float64Array Growth rate per day.
C Float64Array Expected onsets per day, after ascertainment.
f Array.<Float64Array> Delay pmf for each onset day.
F Array.<Float64Array> Delay CDF for each onset day.
pim MissingProb Probability an onset is missing given internal report day and delay.
fbar Float64Array Forward delay: true delay pmf averaged over displayed onsets up to the cut-off, weighted by onsets.
cover Float64Array Expected fraction of each onset day's cases reported by the cut-off.
wk0 number Display day on which week 0 starts. Weeks are counted back from the cut-off, so the last week ends on it.
seed number Seed from the parameters, the default seed for stochastic.
retro boolean Whether the view is retrospective (p.retro).

epidemic-dates.ExpectedData : Object

Output of expectedData. Arrays use the internal day index.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
truth Float64Array Onsets of reported cases by onset day.
comp Float64Array Onsets of cases with a known onset.
miss Float64Array Cases with a missing onset by report day.
rep Float64Array All cases by report day.
empCounts Float64Array Delays of complete cases, length D + 1.

epidemic-dates.EmCallback ⇒ void

Called after each EM iteration.

Kind: static typedef of epidemic-dates

Param Type Description
iteration number Iteration number, from 1.
imputed Float64Array comp plus the allocated cases.
lambda Float64Array The current onset curve λ.

epidemic-dates.MethodResults : Object

Output of runMethods: daily onsets by method on the internal day index, plus the pooled empirical delay and its rounded mean.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
backsampling Float64Array Back-sampling method.
mean Float64Array Mean shift.
fwd Float64Array Forward draw.
gen Float64Array EM back-projection.
g Float64Array Pooled empirical delay pmf.
m number Rounded mean of g.

epidemic-dates.Band : Object

A 90% interval with x the mid-week display day.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
x number Day (wk0 + 7 w + 3.5).
lo number 5% quantile.
hi number 95% quantile.

epidemic-dates.StochasticResult : Object

Output of stochastic. Objects are keyed by method.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
bands Record.<module:epidemic-dates.MethodKey, Array.<module:epidemic-dates.Band>> Weekly relative error.
gbands Record.<module:epidemic-dates.MethodKey, Array.<module:epidemic-dates.Band>> Growth rate per day.
ebands Record.<module:epidemic-dates.MethodKey, Array.<module:epidemic-dates.Band>> Rt error.
truthBand Array.<Band> Growth rate of the true onsets.

epidemic-dates.Metrics : Object

Summary of one method's error against the truth. Relative errors are imputed / truth - 1.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
maxRel number Signed weekly relative error of largest size, over weeks with at least 10 true cases. 0 if none.
maxRelW number Week of maxRel, or -1.
maxG number Signed largest growth rate error (per day).
maxR number Signed largest Rt error.
wrongSide number Weeks where Rt is on the wrong side of 1 (see wrongSideOf1).
meanAbs number Mean absolute weekly relative error over weeks with at least 10 true cases.
lag number zM - zT in days. Positive means the imputed curve turns later.
zT number Day the true growth rate first falls below 0 after being positive, interpolated between mid-weeks.
zM number The same for the imputed curve.
peakShift number Days from the true to the imputed peak week. Null unless the truth has an interior peak with a fall of at least 20% after it.
peakHeight number Relative error of the imputed peak height. Null as for peakShift.
lastWeeks Array.<number> Relative error in each of the last 3 weeks with a value before the cut-off, oldest first. Listed one by one because signed errors can cancel in a mean. Empty when retrospective.
lastMaxAbs number The entry of lastWeeks with the largest absolute value, with its sign. Null when lastWeeks is empty.

epidemic-dates.ComparisonSeries : Object

Output of comparisonSeries.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
truth Float64Array True onsets by day, internal day index.
methods Object.<string, Float64Array> Each method's onsets by day, internal day index.
nowcast boolean Whether the series are truncation corrected.
lastDay Object.<string, ?number> Last display day on which each method has a value, or null for no limit. In real time the mean shift stops at Td − m, where m is the rounded mean pooled delay. Pass to maskWeeks.
m number Rounded mean pooled delay used by the mean shift.

epidemic-dates.RunResult : Object

Weekly results of run. Series are indexed by week. Objects keyed by method hold one entry per METHODS key (backsampling, mean, fwd, gen).

Kind: static typedef of epidemic-dates
Properties

Name Type Description
params ScenarioParams Parameters used.
weekStart Array.<number> First display day of each week.
complete Array.<boolean> Weeks counted as complete: at least 80% reported by the cut-off, or 30% with a nowcast.
truth Array.<number> True onsets of cases reported by the cut-off.
reported Array.<number> All cases by report week.
growth Object.<string, Array.<?number>> Growth rate per day, for truth and each method.
rt Object.<string, Array.<?number>> Rt, for truth and each method.
imputed Object.<string, Array.<?number>> Onsets after imputation, by method. Null in weeks where the method has no value (the mean shift near the cut-off in real time).
metrics Object.<string, module:epidemic-dates.Metrics> Error metrics, by method.
pooledDelay Array.<number> Pooled empirical delay pmf of complete cases (used by backsampling and mean).
forwardDelay Array.<number> Forward delay pmf (used by fwd).

epidemic-dates.LinelistInput : Object

Input to imputeLinelist. Days are whole numbers, for example days since the first report.

Kind: static typedef of epidemic-dates
Properties

Name Type Default Description
onset Array.<?number> Onset day per case, null or undefined where missing.
report Array.<number> Report day per case.
[cutoff] number Last report day to use. Defaults to the latest report day. Later reports are dropped.
[delay] ArrayLike.<number> | ArrayLike.<ArrayLike.<number>> Known forward delay, used as given (a plug-in): one pmf indexed by delay in days, or an array with one pmf per onset day 0..cutoff. If given, fwd uses it and gen holds it fixed. Cannot be combined with delayPeriod.
[maxDelay] number D Longest delay kept. Cases with longer delays are dropped.
[iterations] number 300 EM iterations for gen.
[delayPeriod] number Length in days of the periods of onset days that get their own EM delay, counted back from the cut-off (delayPeriods). Null estimates one static delay.
[delayShrinkage] number DELAY_SHRINKAGE Strength, in expected onsets, of the shrinkage of each period's delay towards the previous period's delay.

epidemic-dates.LinelistResult : Object

Output of imputeLinelist. Daily arrays are indexed by day 0..cutoff and hold expected allocations, so they need not be whole numbers.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
days number Number of days (cutoff + 1).
cutoff number Cut-off used.
dropped number Cases dropped: report day not a whole number in 0..cutoff, or a known onset that is not a whole number, before day 0, after the report or with a delay over maxDelay.
droppedImputed Object Missing-onset cases each method could not place, in expected cases. For backsampling, mean and fwd these are imputed onsets before day 0, or all missing-onset cases for backsampling when there are no complete cases. For gen they are cases reported on a day with no possible onset under the delay. fwd is null without delay.
complete Array.<number> Complete cases by onset day.
missingByReport Array.<number> Missing-onset cases by report day.
empiricalDelay Array.<number> Pooled empirical delay pmf of complete cases.
generativeDelay Array.<number> Delay pmf used by gen: the given delay (its onset-weighted mean for a matrix), the static estimate, or with delayPeriod the pooled estimate.
generativeDelayByPeriod Array.<Array.<number>> Delay pmf of each period. One row without delayPeriod, and one row per onset day for a delay matrix.
delayPeriodStart Array.<number> First onset day of each period.
imputed Object Onsets after imputation by method. fwd is null without delay. gen is not truncation adjusted.

epidemic-dates.NowcastInput : Object

Input to nowcastLinelist. Days are whole numbers, for example days since the first report.

Kind: static typedef of epidemic-dates
Properties

Name Type Default Description
onset Array.<?number> Onset day per case, null or undefined where missing.
report Array.<?number> Report day per case.
[cutoff] number Data cut-off T. Defaults to the latest report day.
[method] string "\"gen\"" Imputation method, one of NOWCAST_METHODS.
[delay] ArrayLike.<number> | ArrayLike.<ArrayLike.<number>> Forward delay, used as given for the truncation correction, for fwd, and held fixed by gen: one pmf indexed by delay in days, or an array with one pmf per onset day 0..T. If null it is estimated by EM. Entries beyond maxDelay are dropped and each pmf renormalised. Cannot be combined with delayPeriod.
[maxDelay] number 60 Longest delay kept, as DMAX in the Python package. Complete cases with longer delays are dropped.
[iterations] number 150 EM iterations for the point fit.
[nSamples] number 1000 Number of samples.
[seed] number 1 Integer seed for makeRng.
[quantiles] ArrayLike.<number> QUANTILES Quantile levels in [0, 1].
[minReported] number 0.05 Smallest fraction reported, F(T − s), for a day to get an estimate. In (0, 1].
[bootstrap] boolean true Resample complete cases to include delay uncertainty.
[origin] string null ISO date of day 0. If given, dates in the quantile tables are ISO strings, otherwise day numbers.
[delayPeriod] number Length in days of the periods of onset days that get their own estimated delay, counted back from the cut-off. Null estimates one static delay.
[delayShrinkage] number DELAY_SHRINKAGE Strength, in expected onsets, of the shrinkage of each period's delay towards the previous period's delay.

epidemic-dates.DailyQuantileRow : Object

One row of a daily quantile table.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
target_end_date number | string Onset day, or its ISO date.
quantile number Quantile level.
value number Quantile of the nowcast.

epidemic-dates.WeeklyQuantileRow : Object

One row of a weekly quantile table.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
week_start number | string First onset day of the week.
target_end_date number | string Last onset day of the week.
quantile number Quantile level.
value number Quantile of the nowcast.

epidemic-dates.NowcastResult : Object

Output of nowcastLinelist. Daily arrays are indexed by onset day 0..cutoff. Weekly arrays have one entry per full week ending on the cut-off. Days and weeks without an estimate hold NaN.

Kind: static typedef of epidemic-dates
Properties

Name Type Description
method string Imputation method used.
cutoff number Cut-off T.
dropped number Cases dropped, as in imputeLinelist.
delay Array.<number> Delay pmf for the point nowcast: the given static delay, the EM estimate, or with periods or a delay matrix the pooled or onset-weighted mean delay.
delayByPeriod Array.<Array.<number>> Delay pmf of each period. Each onset day is its own period when a delay matrix is given.
periodStart Array.<number> First onset day of each period.
reported Array.<number> Fraction reported by the cut-off, Fₛ(T − s), under the delay of the day's period.
point Array.<number> Point nowcast by onset day.
pointWeekly Array.<number> Point nowcast by week.
weekStart Array.<number> First onset day of each week.
samples Array.<Array.<number>> Sampled nowcasts, one array per sample.
weeklySamples Array.<Array.<number>> Sampled weekly nowcasts.
quantiles Array.<number> Quantile levels.
dailyQuantiles Array.<DailyQuantileRow> Long quantile table by day.
weeklyQuantiles Array.<WeeklyQuantileRow> Long quantile table by week.