Skip to contents

Generates a list of retrospective reporting triangles by successively removing rows from the bottom of the original triangle. Each truncated triangle represents what would have been observed at an earlier reference time. This function truncates row(s) of the reporting triangle, removing the most recent observations (starting from the bottom of the reporting triangle).

Usage

truncate_to_rows(
  reporting_triangle,
  n = nrow(reporting_triangle) - sum(is.na(rowSums(reporting_triangle))) - 1,
  validate = TRUE
)

Arguments

reporting_triangle

A reporting_triangle object with rows representing reference times and columns representing delays. Can be a reporting matrix or incomplete reporting matrix. Can also be a ragged reporting triangle, where multiple columns are reported for the same row (e.g., weekly reporting of daily data).

n

Integer indicating the number of retrospective truncated triangles to be generated, always starting from the most recent reference time. Default is to generate truncated matrices for each row up until there are insufficient rows to generate nowcasts from, where the minimum requirement is one more than the number of horizon rows (rows containing NAs).

validate

Logical. If TRUE (default), validates the object. Set to FALSE only when called from functions that already validated.

Value

trunc_rep_tri_list List of n truncated reporting_triangle objects with as many rows as available given the truncation, and the same number of columns as the input reporting_triangle.

See also

Examples

# Generate multiple truncated triangles
truncated_rts <- truncate_to_rows(example_reporting_triangle, n = 2)
truncated_rts[1:2]
#> [[1]]
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2024-01-01 to 2024-01-04
#> Max delay: 3
#> Structure: 1
#> 
#>              0  1  2  3
#> 2024-01-01  80 50 25 10
#> 2024-01-02 100 50 20 NA
#> 2024-01-03  90 45 NA NA
#> 2024-01-04 110 NA NA NA
#> 
#> [[2]]
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2024-01-01 to 2024-01-03
#> Max delay: 3
#> Structure: 2
#> 
#>              0  1  2  3
#> 2024-01-01  80 50 25 10
#> 2024-01-02 100 50 20 NA
#> 2024-01-03  90 45 NA NA
#>