
Apply reporting structure to generate a single retrospective reporting triangle
Source:R/apply_reporting_structure.R
apply_reporting_structure.RdThis function applies a reporting structure to a truncated reporting triangle
by setting observations to NA row by row from the bottom up based on the
specified structure. It is the singular version of
apply_reporting_structures().
Arguments
- truncated_reporting_triangle
A single truncated reporting_triangle object. May or may not contain NAs.
- structure
Integer or vector specifying the reporting structure. If integer, divides columns evenly by that integer (with last possibly truncated). If vector, the sum must not be greater than or equal to the number of columns. Default is 1 (standard triangular structure).
- validate
Logical. If TRUE (default), validates the object. Set to FALSE only when called from functions that already validated.
See also
Retrospective data generation functions
apply_reporting_structures(),
truncate_triangle(),
truncate_triangles()
Examples
# Standard triangular structure (default)
rep_tri <- apply_reporting_structure(example_reporting_triangle)
rep_tri
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2024-01-01 to 2024-01-05
#> Max delay: 3
#> Structure: 1, 0, 1, 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
#> 2024-01-05 95 NA NA NA
# Ragged structure with 2 columns per delay period
rep_ragged <- apply_reporting_structure(example_reporting_triangle, 2)
rep_ragged
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2024-01-01 to 2024-01-05
#> Max delay: 3
#> Structure: 1, 0, 1, 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
#> 2024-01-05 95 NA NA NA
# Custom structure with explicit column counts
rep_custom <- apply_reporting_structure(example_reporting_triangle, c(1, 2))
rep_custom
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2024-01-01 to 2024-01-05
#> Max delay: 3
#> Structure: 1, 0, 1, 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
#> 2024-01-05 95 NA NA NA