Skip to contents

This function ingests a reporting triangle/matrix and the number of truncated reporting triangles we want to create, n, and iteratively truncated the reporting triangle, working from bottom to top for n snapshots.

Usage

truncate_triangles(
  reporting_triangle,
  n = nrow(reporting_triangle) - ncol(reporting_triangle) - 1
)

Arguments

reporting_triangle

Matrix of the reporting triangle/rectangle to be used to generate retrospective triangles, with rows representing the time points of reference and columns representing the delays.

n

Integer indicating the number of retrospective truncated triangles to be generated, always starting from the most recent reference time. Default is to only generate truncated matrices that have sufficient number of rows to generate a nowcast from, though any number can be specified.

Value

trunc_rep_mat_list List of n truncated reporting triangle matrices with as many rows as available given the truncation, and the same number of columns as triangle.

Examples

triangle <- matrix(
  c(
    65, 46, 21, 7,
    70, 40, 20, 5,
    80, 50, 10, 10,
    100, 40, 31, 20,
    95, 45, 21, NA,
    82, 42, NA, NA,
    70, NA, NA, NA
  ),
  nrow = 7,
  byrow = TRUE
)

truncated_rts <- truncate_triangles(
  reporting_triangle = triangle,
  n = 2
)
print(truncated_rts[[1]])
#>      [,1] [,2] [,3] [,4]
#> [1,]   65   46   21    7
#> [2,]   70   40   20    5
#> [3,]   80   50   10   10
#> [4,]  100   40   31   20
#> [5,]   95   45   21   NA
#> [6,]   82   42   NA   NA
print(truncated_rts[[2]])
#>      [,1] [,2] [,3] [,4]
#> [1,]   65   46   21    7
#> [2,]   70   40   20    5
#> [3,]   80   50   10   10
#> [4,]  100   40   31   20
#> [5,]   95   45   21   NA