Learn R Programming

baselinenowcast (version 0.2.0)

sample_nowcasts: Generate multiple draws of a nowcast combining observed and predicted values

Description

Generate multiple draws of a nowcast combining observed and predicted values

Usage

sample_nowcasts(
  point_nowcast_matrix,
  reporting_triangle,
  uncertainty_params,
  draws = 1000,
  ...
)

Value

Dataframe containing information for multiple draws with columns for the reference date (reference_date), the predicted counts (pred_count), and the draw number (draw). Returns predictions for all reference dates in the input reporting_triangle (or fewer if using ref_time_aggregator).

Arguments

point_nowcast_matrix

Matrix of point nowcast predictions and observations, with rows representing the reference times and columns representing the delays.

reporting_triangle

A reporting_triangle object with rows representing reference times and columns representing delays. Can be a reporting matrix or incomplete reporting matrix. Can also be a ragged reporting triangle, where multiple columns are reported for the same row (e.g., weekly reporting of daily data).

uncertainty_params

Vector of uncertainty parameters ordered from horizon 1 to the maximum horizon. Note that these will be reversed internally to match the ordering of the point_nowcast_matrix (where a horizon of 1 is the last entry).

draws

Integer indicating the number of draws of the predicted nowcast vector to generate. Default is 1000.

...

Additional arguments passed to sample_nowcast.

See Also

Probabilistic nowcast generation functions combine_obs_with_pred(), sample_nb(), sample_nowcast(), sample_prediction(), sample_predictions()

Examples

Run this code
# Generate point nowcast and uncertainty params from example data
data_as_of <- syn_nssp_df[syn_nssp_df$report_date <= "2026-04-01", ]
rep_tri <- as_reporting_triangle(data_as_of) |>
  truncate_to_delay(max_delay = 5) |>
  tail(n = 10)
point_nowcast_matrix <- estimate_and_apply_delay(rep_tri, n = 10)
reporting_triangle <- apply_reporting_structure(rep_tri)
uncertainty_params <- estimate_uncertainty_retro(
  rep_tri,
  n_history_delay = 8,
  n_retrospective_nowcasts = 2
)
nowcast_draws <- sample_nowcasts(
  point_nowcast_matrix,
  reporting_triangle,
  uncertainty_params,
  draws = 5
)
nowcast_draws

Run the code above in your browser using DataLab