Learn R Programming

baselinenowcast (version 0.2.0)

reporting_triangle-class: Reporting Triangle Object

Description

A reporting_triangle object contains the data and metadata needed for nowcasting.

Arguments

Value

A reporting_triangle object. This is a matrix subclass containing case counts indexed by reference date (rows) and delay (columns). See the Structure section for details on the object format.

Structure

A reporting_triangle is a matrix with class c("reporting_triangle", "matrix"):

  • Rows: Reference dates

  • Columns: Delays (0, 1, 2, ...)

  • Entries: Incident cases at each reference date and delay

  • Row names: Reference dates as character

  • Column names: Delays as character

Attributes:

  • delays_unit: Character ("days", "weeks", "months", "years")

Reference dates are stored as row names and can be extracted using get_reference_dates(). The maximum delay can be obtained using get_max_delay(). The structure can be computed using get_reporting_structure(). See the corresponding as_reporting_triangle.matrix() and as_reporting_triangle.data.frame() functions for more details on the required input formats to generate the object.

Working with reporting triangles

Reporting triangle objects provide:

Inspection and display:

Subsetting and modification:

  • [ and [<-: Extract or assign values with automatic validation

  • Subsetting preserves class and attributes when result is a matrix

Package functions:

  • estimate_and_apply_delay(): Estimate delay and generate point nowcast

  • estimate_delay(): Extract delay distribution from triangle

  • apply_delay(): Apply delay distribution for nowcasting

  • truncate_to_row(): Remove most recent rows

  • preprocess_negative_values(): Handle reporting corrections

See Also

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(), 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(), summary.reporting_triangle(), tail.reporting_triangle(), truncate_to_delay(), truncate_to_quantile(), validate_reporting_triangle()

Examples

Run this code
# Create a reporting triangle from data
data <- syn_nssp_df[syn_nssp_df$report_date <= "2026-04-01", ]
rep_tri <- as_reporting_triangle(data = data)

# Use with low-level functions
filled <- estimate_and_apply_delay(rep_tri)
delay_pmf <- estimate_delay(rep_tri)
nowcast <- apply_delay(rep_tri, delay_pmf)

# Direct matrix operations
total_by_date <- rowSums(rep_tri, na.rm = TRUE)
total_by_delay <- colSums(rep_tri, na.rm = TRUE)

# Subsetting and inspection
recent <- tail(rep_tri, n = 10)
summary(rep_tri)

Run the code above in your browser using DataLab