Skip to contents

This method takes a matrix in the format of a reporting triangle, with rows as reference dates and columns as delays and elements as incident case counts and creates a reporting_triangle object. See as_reporting_triangle.data.frame() for creating from data frames.

Usage

# S3 method for class 'matrix'
as_reporting_triangle(data, delays_unit = "days", reference_dates = NULL, ...)

Arguments

data

Matrix of a reporting triangle where rows are reference times, columns are delays, and entries are the incident counts. The number of columns determines the maximum delay.

delays_unit

Character string specifying the temporal granularity of the delays. Options are "days", "weeks", "months", "years". Default is "days".

reference_dates

Vector of Date objects or character strings indicating the reference dates corresponding to each row of the reporting triangle matrix (data). If NULL (default), dummy dates starting from 1900-01-01 are generated with spacing determined by delays_unit.

...

Additional arguments not used.

Value

A reporting_triangle object

Examples

rep_tri_mat <- matrix(
  c(
    1, 3, 5, 7, 9,
    4, 7, 8, 0, NA,
    9, 10, 0, NA, NA,
    3, 0, NA, NA, NA,
    6, NA, NA, NA, NA
  ),
  nrow = 5,
  byrow = TRUE
)

reference_dates <- seq(
  from = as.Date("2025-01-01"),
  to = as.Date("2025-01-05"),
  by = "day"
)

# max_delay is inferred from matrix dimensions (4 in this case)
rep_tri <- as_reporting_triangle(
  data = rep_tri_mat,
  reference_dates = reference_dates
)
rep_tri
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2025-01-01 to 2025-01-05
#> Max delay: 4
#> Structure: 1
#> 
#>            0  1  2  3  4
#> 2025-01-01 1  3  5  7  9
#> 2025-01-02 4  7  8  0 NA
#> 2025-01-03 9 10  0 NA NA
#> 2025-01-04 3  0 NA NA NA
#> 2025-01-05 6 NA NA NA NA