Skip to content

Add 12-month ensemble forecast to the Lines tab - #18

Merged
viniciusoike merged 3 commits into
mainfrom
feature/line-forecast-mock
Oct 20, 2026
Merged

viniciusoike merged 3 commits into
mainfrom
feature/line-forecast-mock

Conversation

@viniciusoike

@viniciusoike viniciusoike commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Adds a 12-month demand forecast to the Lines tab. The forecast appears when a single line is selected and the new "Mostrar projeção (12 meses)" checkbox is on.

Model

  • Equal-weight ensemble of STL + ETS, ETS, and ARIMA with calendar regressors, fitted on log demand since Jan 2022, so the 2020–21 collapse and recovery stay out of the fit.
  • Calendar regressors are the business days and non-holiday Saturdays per month, built from metrosp::calendar_spo.
  • In a rolling-origin backtest, the ensemble's MAPE was 3.5%, against 4.1% for the best single model (ARIMA with calendar). Blanking the pandemic months and fitting from 2016 did worse (7.3%).

Intervals

  • The 90% intervals are empirical. tools/forecast-backtest.R pools the ensemble's log errors by horizon across lines, after standardizing each by its series' residual SD, and writes the quantiles to data/forecast-quantiles.csv. The app reads that file at startup.
  • The quantiles are forced to widen (or stay flat) with the horizon.
  • Coverage is 92–97% for Lines 1–4, 86% for Line 15 and 81% for Line 5. Line 5 is biased upward.

App changes

  • A fifth KPI card shows the projected 12-month growth with its interval.
  • The Lines CSV includes fc_mean, fc_lower and fc_upper rows when the forecast is on.
  • forecast and its dependencies are added to renv.lock.
  • tools/check-manifest.R now also covers data/.

Dependencies

  • renv.lock was re-snapshotted with r-universe listed as a repository, so metrosp and trendseries (now 1.7.0) are pinned to r-universe.
  • manifest.json was regenerated. It now records both packages from r-universe, plus forecast and data/forecast-quantiles.csv.

🤖 Generated with Claude Code

viniciusoike and others added 3 commits October 4, 2026 18:26
Equal-weight ensemble of STL + ETS, ETS and ARIMA with São Paulo
calendar regressors, fitted on log demand since Jan 2022. Adds a
forecast KPI card and forecast columns in the Lines CSV.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Replace the averaged member bounds with empirical 90% intervals. A
rolling-origin backtest (tools/forecast-backtest.R) pools the
ensemble's standardized log errors by horizon across lines and writes
their quantiles to data/forecast-quantiles.csv. The forecast KPI card
now shows an interval for the 12-month growth.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Re-snapshot with r-universe listed in the lockfile repositories, so
rsconnect records both packages from r-universe instead of falling
back to CRAN. Regenerate manifest.json with forecast and the forecast
quantiles file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@viniciusoike
viniciusoike merged commit 856a76c into main Oct 20, 2026
1 check passed
viniciusoike added a commit that referenced this pull request Oct 20, 2026
Resolve the manifest.json conflict by taking main's file list and
dropping local-only files that rsconnect picked up during PR #18:
.claude/, .omx/, .playwright-mcp/, .posit/ and .Rprofile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant