
Convert reviser vintages to reporting_triangle format
Source:R/as_reviser_vintages.R
as_reporting_triangle.tbl_pubdate.RdThis S3 method converts a reviser vintages object (wide format, class
tbl_pubdate) to a reporting_triangle object, enabling use of
baselinenowcast's nowcasting methods.
Usage
# S3 method for class 'tbl_pubdate'
as_reporting_triangle(data, delays_unit = NULL, ...)Arguments
- data
A reviser vintages object in wide format (class
tbl_pubdate), with atimecolumn and one column per publication date.- delays_unit
Character string specifying the temporal granularity of the delays, one of
"days","weeks","months", or"years". IfNULL(default), the unit is inferred from the smallest non-zeropub_date - timegap indata(1 day ->"days", 7 days ->"weeks"). Pass it explicitly to override or for monthly/yearly triangles.- ...
Additional arguments passed to
as_reporting_triangle.data.frame().
Value
A reporting_triangle object. See reporting_triangle for details on the structure.
Details
Reviser vintages store cumulative reported values at each publication date.
The conversion takes differences between successive publication dates per
time point to recover incremental counts, and uses the delay implied by
pub_date - time (in delays_unit) to build the reporting triangle.
A tbl_pubdate carries no record of which delay unit was used when the
vintages were created. By default this function infers delays_unit from
the realised delays (the gaps between each pub_date and its time),
which means weekly reference dates with daily delays are correctly
inferred as "days" and vice versa. Pass delays_unit explicitly to
override the inference or for monthly/yearly triangles.
The reviser package must be installed to use this function.
See also
as_reviser_vintages()for converting to reviser vintagesas_reporting_triangle.data.frame()for the underlying method
Reporting triangle construction and validation
[.reporting_triangle(),
[<-.reporting_triangle(),
as.data.frame.reporting_triangle(),
as.matrix.reporting_triangle(),
as_ChainLadder_triangle(),
as_reporting_triangle(),
as_reporting_triangle.data.frame(),
as_reporting_triangle.matrix(),
as_reporting_triangle.triangle(),
as_reviser_vintages(),
assert_reporting_triangle(),
get_delays_from_dates(),
get_delays_unit(),
get_max_delay(),
get_mean_delay(),
get_quantile_delay(),
get_reference_dates(),
get_report_dates(),
get_reporting_structure(),
head.reporting_triangle(),
is_reporting_triangle(),
new_reporting_triangle(),
print.reporting_triangle(),
reporting_triangle-class,
summary.reporting_triangle(),
tail.reporting_triangle(),
truncate_to_delay(),
truncate_to_quantile(),
validate_reporting_triangle()
Examples
# Create a reporting triangle
data_as_of_df <- syn_nssp_df[syn_nssp_df$report_date <= "2026-04-01", ]
rep_tri <- as_reporting_triangle(data = data_as_of_df)
#> ℹ Using max_delay = 154 from data
# Convert to reviser vintages
vintages <- as_reviser_vintages(rep_tri)
# Convert back to reporting_triangle; `delays_unit` is inferred from the
# spacing of the `time` column.
rep_tri_2 <- as_reporting_triangle(data = vintages)
#> ℹ Using max_delay = 154 from data
print(rep_tri_2)
#> Reporting Triangle
#> Delays unit: days
#> Reference dates: 2025-10-25 to 2026-04-01
#> Max delay: 154
#> Structure: 1
#>
#> Showing last 10 of 159 rows
#> Showing first 10 of 155 columns
#>
#> 0 1 2 3 4 5 6 7 8 9
#> 2026-03-23 210 131 34 50 35 12 1 25 20 6
#> 2026-03-24 221 96 22 10 13 6 0 5 9 NA
#> 2026-03-25 291 129 17 26 42 29 23 25 NA NA
#> 2026-03-26 179 96 22 50 9 8 18 NA NA NA
#> 2026-03-27 284 40 41 54 28 12 NA NA NA NA
#> 2026-03-28 217 78 46 14 39 NA NA NA NA NA
#> 2026-03-29 336 161 62 13 NA NA NA NA NA NA
#> 2026-03-30 296 53 55 NA NA NA NA NA NA NA
#> 2026-03-31 210 108 NA NA NA NA NA NA NA NA
#> 2026-04-01 236 NA NA NA NA NA NA NA NA NA
#>
#> Use print(x, n_rows = NULL, n_cols = NULL) to see all data