
Convert between tbl_now and baselinenowcast
tbl_now_baselinenowcast.Rdtbl_now_from_baselinenowcast() accepts either the long data.frame
(reference_date, report_date, count) or a reporting_triangle
matrix (rownames = reference dates, colnames = delays, incremental counts)
and converts it into a tbl_now of data_type = "count-incidence".
tbl_now_to_baselinenowcast() returns either a reporting_triangle matrix
(format = "matrix", the default) via
baselinenowcast::as_reporting_triangle(), or the long
baselinenowcast-style data.frame (format = "long"). The long format also
carries the
covariates, the censoring indicator and any materialised temporal-effect
columns (see compute_temporal_effects()); the matrix holds only the three
core columns.
Usage
tbl_now_from_baselinenowcast(
data,
...,
reference_date = "reference_date",
report_date = "report_date",
count = "count",
delays_unit = "days",
verbose = TRUE
)
tbl_now_to_baselinenowcast(
x,
...,
format = c("matrix", "long"),
delays_unit = "days",
verbose = TRUE
)Arguments
- data
A long
data.frameor areporting_trianglematrix.- ...
Forwarded to
as_tbl_now()(from) orbaselinenowcast::as_reporting_triangle()(to, matrix format).- reference_date, report_date, count
Column names (long format only).
- delays_unit
Unit of the delay axis (passed to
baselinenowcast::as_reporting_triangle()). Defaults to"days".- verbose
Logical. Print the choices that were made.
- x
A
tbl_nowobject.- format
For
to:"matrix"(default) or"long".
Round-trip
A reporting_triangle distinguishes not-yet-observed cells (NA) from
observed zeros (0). The NA cells split at the last observed report
date (the latest report with a non-NA count, taken as the nowcast's now):
cells with
report_date > noware * not-yet-observable* future cells. They are dropped from thetbl_now().cells with
report_date <= nowcould have been reported but were not. They are genuinely missing and kept ascount = NArows in thetbl_now().
On the way back, baselinenowcast::as_reporting_triangle() fills the
in-triangle cells with 0 unless they are marked in the tibble as NA.
Examples
# Get a reporting triangle example
rt <- baselinenowcast::example_reporting_triangle
# Convert to a tbl_now
nowobj <- tbl_now_from_baselinenowcast(rt)
#>
#> ── Converted baselinenowcast <data> into a <tbl_now>
#> • event_date: "reference_date"
#> • report_date: "report_date"
#> • data_type: "count-incidence"
#> • now: "2024-01-07"
#> • event_units: "days"
#> • report_units: "days"
#> • case_count: "count"
#> • expanded a reporting-triangle matrix to long counts
# The matrix round-trip is faithful (not-yet-observed `NA` cells are kept).
identical(rt, tbl_now_to_baselinenowcast(nowobj))
#>
#> ── Converting <tbl_now> to baselinenowcast matrix
#> • reference_date <- "reference_date"
#> • report_date <- "report_date"
#> • count <- "count"
#> • format: "matrix"
#> ℹ Using max_delay = 3 from data
#> [1] TRUE