
Convert between tbl_now and EpiNow2
tbl_now_EpiNow2.RdEpiNow2 takes four different input shapes, one per entry point, so
tbl_now_to_EpiNow2() is told which one you want with target – named after
the EpiNow2 function the result is passed to, so it can be handed over
unchanged:
"estimate_infections"a
data.frameofdate/confirm, the series as known atget_now(). Also whatEpiNow2::epinow()takes."regional_epinow"the same, plus a
regioncolumn built from the object's strata."estimate_truncation"a tbl_now_epinow2_snapshots list – one
date/confirmsnapshot per report date, which is the one EpiNow2 model that uses the report dimension atbl_nowexists to carry."estimate_dist"the interval-censored
pdate_lwr/pdate_upr/sdate_lwr/sdate_upr/obs_dateframe thatEpiNow2::estimate_dist()fits a delay distribution to (new in EpiNow2 1.9.0). Count data rides along as thenweight column.
tbl_now_from_EpiNow2() inverts the snapshot form: snapshot k is the series
as known at report date k, so differencing consecutive snapshots recovers
count-incidence exactly. There is deliberately no inverse for the other
three: a single series has no report dimension to recover, and a delay
distribution is not case data.
Usage
tbl_now_to_EpiNow2(
x,
...,
target = c("estimate_infections", "regional_epinow", "estimate_truncation",
"estimate_dist"),
snapshots = NULL,
accumulate = "auto",
verbose = TRUE,
quiet = FALSE
)
tbl_now_from_EpiNow2(data, ..., report_dates = NULL, verbose = TRUE)Arguments
- x
A
tbl_nowobject.- ...
Forwarded to
as_tbl_now()(from); unused (to).- target
Which EpiNow2 entry point the result is for. See above.
- snapshots
For
"estimate_truncation": how many snapshots to emit, taken from the latest report dates.NULL(default) uses 5, matchingEpiNow2::example_truncated. One snapshot per distinct report date is usually far more than the model can fit.- accumulate
How to handle non-daily data.
"auto"(default) lays a weekly series on EpiNow2's daily grid with anaccumulatecolumn;FALSEpasses the rows through unchanged, which is almost always wrong (see Non-daily data). Ignored for"estimate_dist", which works in censoring windows rather than on a grid.- verbose
Logical. Print the choices that were made.
- quiet
Logical. A different channel from
verbose:verbosecontrols the informational summary of what the conversion did, whilequietsuppresses the lossy-conversion warning. Set both to keep a conversion entirely silent.- data
A tbl_now_epinow2_snapshots, or a plain list of
date/confirmdata frames (e.g.EpiNow2::example_truncated), in which casereport_datesis required.- report_dates
For
from: aDatevector, one per snapshot, saying when each was taken. Read from the object's attribute when it has one.
Value
For to, a data.frame or a tbl_now_epinow2_snapshots, according to
target. For from, a tbl_now of data_type = "count-incidence".
Non-daily data
EpiNow2 models a daily process. As of 1.9.0 there is no timestep,
interval or period argument on any of its entry points, so a weekly series
passed as one row per week is read as one row per day and the fit is
silently wrong on the time axis – no error, just an epidemic seven times too
fast.
Its own answer is the accumulate column (see EpiNow2::fill_missing()): the
series is laid on a daily grid and the filler days are marked to be added to
the next real observation. accumulate = "auto" does this from
get_event_units(). Units coarser than a week, and the "numeric" grid, are
refused outright rather than approximated.
What EpiNow2 will not take
EpiNow2::estimate_secondary()models two data streams (cases and deaths, say) against each other. Onetbl_nowis one stream, so there is no honest mapping and no target for it.EpiNow2::estimate_delay()takes a bare vector of delays. Its own help now points atestimate_dist()as "the recommended replacement", and it throws away the censoring atbl_nowcarries, so there is no target for it either. If you want it anyway, it isx$.delay.
See also
tbl_now_to_epidist(), which builds the same censoring windows as
target = "estimate_dist" – the two are different front ends onto one
delay-distribution schema.
Examples
data(denguedat)
nowobj <- tbl_now(denguedat[1:2000, ],
event_date = "onset_week", report_date = "report_week", verbose = FALSE
)
## A single daily series for estimate_infections() -- the weekly data is laid
# on EpiNow2's daily grid.
head(tbl_now_to_EpiNow2(nowobj, verbose = FALSE, quiet = TRUE))
#> date confirm accumulate
#> 1 1989-12-26 NA TRUE
#> 2 1989-12-27 NA TRUE
#> 3 1989-12-28 NA TRUE
#> 4 1989-12-29 NA TRUE
#> 5 1989-12-30 NA TRUE
#> 6 1989-12-31 NA TRUE
## Snapshots for estimate_truncation(), which uses the report dimension.
snaps <- tbl_now_to_EpiNow2(nowobj,
target = "estimate_truncation", verbose = FALSE, quiet = TRUE
)
snaps
#> ── 5 reporting snapshots from a <tbl_now> ──────────────────────────────────────
#> • One per report date: "1991-01-21", "1991-01-28", "1991-02-11", "1991-02-25", and "1991-03-04"
#> • Rows each: 357, 357, 357, 357, and 357
#> • Now: "1991-03-04"
#> ℹ Pass this to `EpiNow2::estimate_truncation()`. `EpiNow2::estimate_secondary()` wants a single data frame of linked series instead -- not this.