
The settled (eventually-observed) total per reference week
Source:R/nowcast_backtest.R
nowcast_truth.RdSums each reference week's counts across delays `0` to `max_delay - 1` – the quantity a nowcast is trying to predict – and keeps only weeks old enough that this total is settled, meaning at least `max_delay - 1` weeks before the triangle's as-of. Both bounds are one lower than they may read: `max_delay = 3` sums delays 0, 1 and 2, and the newest settled reference week is 2 weeks before as-of, not 3. Anything reported at a delay of `max_delay` or more falls outside this total, so it is a horizon-capped truth, not the eventual one.
See also
vignette("pipeline", package = "csalert") calls this
function directly in its validation stage to obtain settled truth.
nowcast_evaluate_v1 calls it for you when you only want the
scores.
Other nowcast diagnostics:
nowcast_backtest(),
nowcast_censor(),
nowcast_evaluate_v1()
Examples
w <- cstime::dates_by_isoyearweek$isoyearweek
i <- match("2023-01", w)
set.seed(1)
d <- data.table::data.table(
isoyearweek_reference = w[i + rep(0:39, each = 3)],
isoyearweek_reporting = w[i + rep(0:39, each = 3) + rep(0:2, 40)],
numerator = rpois(120, c(30, 15, 5)),
indicator_tag = "x", location_code = "nation", age = "total", sex = "total"
)
d <- d[isoyearweek_reporting <= w[i + 39]]
tri <- csfmt_reporting_triangle_v3(
d,
id_cols = c("indicator_tag", "location_code", "age", "sex")
)
truth <- nowcast_truth(tri, max_delay = 3)
# the two newest weeks are missing: they are not settled yet, so they have no
# truth to be scored against
tail(truth, 3)
#> reference truth
#> <char> <num>
#> 1: 2023-36 44
#> 2: 2023-37 43
#> 3: 2023-38 51
c(reference_weeks = 40L, settled = nrow(truth))
#> reference_weeks settled
#> 40 38