
Convert a baselinenowcast_df object to a forecast_point object
Source: R/as_forecast_sample.R
as_forecast_point.baselinenowcast_df.RdThis function converts a point baselinenowcast_df object as returned by
baselinenowcast() with output_type = "point" to a forecast_point
object which can be used for scoring with the
scoringutils package.
Usage
# S3 method for class 'baselinenowcast_df'
as_forecast_point(
data,
latest_obs,
observed = "count",
model = "baselinenowcast",
...
)Arguments
- data
A baselinenowcast_df object as returned by
baselinenowcast()withoutput_type = "point".- latest_obs
A data.frame containing the truth to score against, with one row per (reference_date, strata) combination. Must contain a
reference_datecolumn and a column with observed counts named according toobserved(default"count"). Additional columns shared withdata(such as strata columns) are used as merge keys.latest_obsshould hold the reported total at each reference date evaluated at the samemax_delayhorizon used for the nowcast (rolling truth), not the partial total available when the nowcast was run.- observed
Character string giving the name of the column in
latest_obsthat holds the observed value. Defaults to"count"to match the input format ofbaselinenowcast.data.frame().- model
Character string used as the value of the
modelcolumn on the returned forecast object. Letsscoringutils::summarise_scores()run with its defaultby = "model". Defaults to"baselinenowcast". PassNULLto omit the column (e.g. whendataalready carries its ownmodelcolumn).- ...
Additional arguments passed to
scoringutils::as_forecast_point().
Value
A forecast_point object as returned by
scoringutils::as_forecast_point().
Details
The nowcast point estimates in data are merged with the latest
observations in latest_obs on reference_date and any other shared
columns and then passed to scoringutils::as_forecast_point(), using
pred_count as the predicted value and the column named by observed as
the observed value.
Examples
if (FALSE) { # interactive() && requireNamespace("scoringutils", quietly = TRUE)
library(scoringutils)
max_delay <- 25
nowcast_date <- as.Date("2026-04-01")
full_tri <- as_reporting_triangle(syn_nssp_df) |>
truncate_to_delay(max_delay = max_delay)
n_drop <- sum(as.Date(rownames(full_tri)) > nowcast_date)
rep_tri <- full_tri |>
truncate_to_row(t = n_drop) |>
apply_reporting_structure() |>
tail(n = 40)
nowcast <- baselinenowcast(rep_tri, output_type = "point")
# Rolling truth from the same full triangle. `as_forecast_point()` scores
# only the right-truncated nowcast dates (the `nowcast` column); the
# inner-join merge restricts the truth to those dates.
truth_df <- as.data.frame(full_tri)
latest_obs <- aggregate(count ~ reference_date, data = truth_df, FUN = sum)
fp <- as_forecast_point(nowcast, latest_obs)
fp
scores <- score(fp)
scores
summarise_scores(scores)
}