Forecast workflow toolkit for UHERO’s quarterly macro model. The package wraps data preparation, equation management, estimation, simulation, and reporting into a set of reproducible R functions that can be called from scripts, targets pipelines, or interactively.
Installation
# install dependencies declared in DESCRIPTION (fcutils, bimets, etc.)
remotes::install_github("UHERO/fcflow")
# optional: restore the exact development environment
renv::restore()Development scripts assume the project is opened in RStudio (or similar) with the working directory set to the repository root so that here::here() resolves correctly.
Repository layout
| Path | Purpose |
|---|---|
R/ |
Exported functions such as make_data_main(), solve_model(), select_model(). |
inst/extdata/config/ |
Template YAML configurations. Copy config.yml into config/ and edit for a specific vintage. |
inst/extfuns/ |
User-editable helper scripts for wrangling, extending history, importing add-factors, and creating plot lists. |
data/raw, data/processed, equations, output/figures
|
Default directories referenced in the config (paths node). |
tools/pack_dev.R |
Notes on setting up the development environment. |
Configuration
Use fcflow::load_forecast_cfg() to read the active configuration. The loader searches in this order:
- The explicit
pathargument. -
Sys.getenv("MODDEV_CONFIG"). -
here::here("config", "config.yml"). - The packaged default (
inst/extdata/config/config.ymlinstalled withfcflow).
Key sections in the YAML file:
-
vintages: current (curr) and comparison (comp) vintage labels. -
paths: locations of raw/processed data, equations, figure output, and the helper scripts that are sourced viarun_script_with_args(). Update these entries if you relocate the scripts frominst/extfuns/. -
data_main,data_model,make_model,solve_model,plot_forecast,data_gets,select_model: module-specific settings controlling filenames, toggles (e.g.,update_equations), date ranges, and save locations. -
combine_equations: which*_eq.txtfiles to stitch together and where to cache the combinedmodel_equations.txt/.RDS.
Core workflow functions
All exported functions accept the configuration object produced by load_forecast_cfg() and can take pre-loaded data objects to avoid redundant disk I/O.
-
combine_equations(cfg): reads the BIMETS equation snippets located underpaths$equations, filters bycombine_equations$equations_subset, and producesmodel_equations.txtand.RDS. -
make_data_main(cfg, indicators = NULL): pulls history (either from disk or viafcutils::get_series_exp()), appliesextend_scriptandwrangl_script, and writesdata_main.csv/.RDStopaths$processed. -
make_data_model(cfg, data_main, model_equations): restricts the master set to the variables required by the model and chains in pseudo-exogenous series viaimpexf_script(defaultinst/extfuns/import_existing_forecast.R). -
make_model(cfg, data_model, model_equations): estimates behavioral equations (optionally discovering or forcing TSRANGE), initializes zero add factors, and records the ragged edge metadata. -
solve_model(cfg, estimated_equations, exog_range, add0_factors): sources the add-factor script (paths$addfac_script), runs the BIMETS simulation, and savesforecast.csv/.RDSplus the add-factor log. -
plot_forecast(cfg, forecast, comparison_forecast, history): assembles history/current/comparison vintages, selects the plot universe using the tourism or macro plot list script, and writes interactive HTML charts topaths$figures.
Each function returns a named list so that outputs can be piped into the next step without needing to touch the filesystem.
Model selection and GETS
-
make_data_gets(cfg, data_main, existing_forecast): chains the historical dataset with the pseudo-forecast to create the extended panel used for GETS. Outputsdata_main_extended.csv/.RDS. -
select_model(cfg, model_select_data, indicators): orchestrates the GETS / ISAT workflow defined inselect_modelconfig nodes, saves a candidate equation (model_eq.txt), compiles and estimates it via BIMETS, and produces diagnostic plots inpaths$figures.
Both functions honor the same path conventions as the core workflow and rely on inst/extfuns/model_selection.R for interactive experimentation.
Helper scripts
The scripts under inst/extfuns/ are templates that get sourced at runtime:
-
wrangle_data.R: apply data adjustments that used to live in add-factor files (seasonal dummy tweaks, zeroing pandemic periods, derived ratios, etc.). -
extend_qmain_history.R: splice additional history from archived AREMOS TSVs. -
import_existing_forecast.R: load QSOL/ASOL files, disaggregate annual series, construct real values, and ensure exogenous drivers exist for every equation. -
add_qmod.R: customize add factors prior to solving the model. -
qsol_plot_list.R/toursol_plot_list.R: define which mnemonics appear in macro vs. tourism dashboards. -
forecast_work.R: convenience script to run any subset of the workflow by toggling booleans inrun_steps.
Copy these files into the locations referenced by paths (or point the config to the copies inside inst/extfuns/) before running the package functions.
Typical run
library(fcflow)
cfg <- load_forecast_cfg() # read config/config.yml or fallback
equations <- combine_equations(cfg)
data_main <- make_data_main(cfg)$data_main
data_model <- make_data_model(cfg,
data_main = data_main,
model_equations = equations$model_equations)
est <- make_model(cfg,
data_model = data_model$data_model,
model_equations = data_model$model_equations)
fcst <- solve_model(cfg,
estimated_equations = est$estimated_equations,
exog_range = est$exog_range,
add0_factors = est$add0_factors)
plots <- plot_forecast(cfg, forecast = fcst$forecast)Swap any of the intermediate arguments with NULL to fall back to previously saved artifacts on disk.
Development
- Use
renv::restore()to install compatible dependency versions. - Run
devtools::document(),devtools::check(), andpkgdown::build_site()before opening a PR. - The GitHub action
R-CMD-checkmirrors the standarddevtools::check()run, so ensure it passes locally when possible.