Learn R Programming

baselinenowcast (version 0.2.0)

sample_predictions: Get a dataframe of multiple draws of only the predicted elements of the nowcast vector

Description

Get a dataframe of multiple draws of only the predicted elements of the nowcast vector

Usage

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

Value

Dataframe containing the predicted point nowcast vectors indexed by predicted count (pred_count), reference date (reference_date), and the draw index (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_prediction.

See Also

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

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_pred_draws <- sample_predictions(
  point_nowcast_matrix,
  reporting_triangle,
  uncertainty_params,
  draws = 5
)
nowcast_pred_draws

# Get nowcast pred draws over rolling sum
if (requireNamespace("zoo", quietly = TRUE)) {
  nowcast_pred_draws_rolling_df <- sample_predictions(
    point_nowcast_matrix,
    reporting_triangle,
    uncertainty_params,
    draws = 5,
    ref_time_aggregator = function(x) zoo::rollsum(x, k = 2, align = "right")
  )
  nowcast_pred_draws_rolling_df
}

Run the code above in your browser using DataLab