Orchestrates nowcast generation for multiple geographic locations, with optional parallel processing. Wraps each location in error handling to continue processing even if individual locations fail.
This function handles the full pipeline from cumulative reporting data
(as returned by fetch_reporting_data()) to nowcast results, including
conversion to incremental counts internally.
Usage
run_state_nowcasts(
data,
config,
location_configs = NULL,
locations = "all",
nowcast_date = NULL,
cumulative = TRUE,
parallel = FALSE
)Arguments
- data
A data frame of reporting data as returned by
fetch_reporting_data(), containing columnsreference_date,report_date,count,location, andsignal.- config
A
nowcast_configobject to use as the default for all locations.- location_configs
Optional named list of
nowcast_configobjects keyed by location code (e.g.,list(ca = config_ca, ny = config_ny)). These override the defaultconfigfor specific locations.- locations
Character vector. Either
"all"for all available locations in the data, or a character vector of specific location codes (e.g.,c("ca", "ny")). Default is"all".- nowcast_date
Date. The date to use as the nowcast date. Defaults to the maximum report_date in the data.
- cumulative
Logical. If
TRUE(the default), the input data is assumed to be cumulative counts (as returned byfetch_reporting_data()) and will be converted to incremental counts usingcumulative_to_incremental(). Set toFALSEif the data is already incremental.- parallel
Logical. Whether to use parallel processing via
purrr::in_parallel(). Requires themiraipackage. Default isFALSE.
Value
A data frame with columns:
reference_date: The reference date being nowcastedlocation: Geographic identifierpred_count: Predicted count (one row per draw)draw: Draw numberoutput_type: Type of output ("samples" or "point")
The returned data frame has an attribute failed_locations containing
a character vector of any locations that failed to process.
Examples
if (FALSE) { # \dontrun{
# Fetch cumulative data for states
source <- delphi_epidata_source(target = "covid", geo_types = "state")
data <- fetch_reporting_data(source, reference_dates, report_dates)
# Single config for all locations
config <- nowcast_config()
results <- run_state_nowcasts(data, config, locations = c("ca", "ny"))
# Override config for specific locations
config <- nowcast_config(draws = 500)
location_configs <- list(
ca = nowcast_config(max_delay = 5, draws = 500),
ny = nowcast_config(max_delay = 7, uncertainty_model = "skellam", draws = 500)
)
results <- run_state_nowcasts(
data, config,
location_configs = location_configs,
locations = c("ca", "ny", "tx")
)
# ca and ny use their specific configs, tx uses the default
# Check for failures
attr(results, "failed_locations")
} # }