
Cut a reporting triangle back to what was known on a past date
Source:R/nowcast_backtest.R
nowcast_censor.RdKeeps the cells reported on or before as_of, and rebuilds the triangle. That
is exactly what an engine saw on that date only when the reporting system
never corrects or deletes a count.
See also
vignette("pipeline", package = "csalert"), stage 2.
Other nowcast diagnostics:
nowcast_backtest(),
nowcast_truth()
Examples
# 40 reference weeks, each reported 3, 10 and 17 days after its Monday
monday <- as.Date("2023-01-02") + 7 * rep(0:39, each = 3)
set.seed(1)
d <- data.table::data.table(
isoyearweek_reference = format(monday, "%G-%V"),
reporting_date = monday + rep(c(3, 10, 17), 40),
numerator = rpois(120, c(30, 15, 5)),
indicator_tag = "x", location_code = "nation", age = "total", sex = "total"
)
d <- d[reporting_date <= as.Date("2023-01-02") + 7 * 39 + 6]
tri <- csfmt_reporting_triangle_v3(
d,
id_cols = c("indicator_tag", "location_code", "age", "sex")
)
# go back to what was known nine weeks earlier
past <- nowcast_censor(tri, as_of = as.Date("2023-01-02") + 7 * 30 + 6)
c(now = attr(tri, "as_of"), then = attr(past, "as_of"))
#> now then
#> "2023-10-05" "2023-08-03"
c(rows_now = nrow(tri), rows_then = nrow(past))
#> rows_now rows_then
#> 117 90