A technical working paper for this package can be found here.
nowcast is an R package for economic nowcasting. It estimates the current state of a macroeconomic variable (like GDP) before the official data are released, using higher-frequency indicators that are available sooner.
install.packages("nowcast")
# Or install the development version from GitHub
# install.packages("devtools")
# devtools::install_github("charlescoverdale/nowcast")
install.packages("nowcast", repos = c('https://charlescoverdale.r-universe.dev', 'https://cloud.r-project.org'))
library(nowcast)
# Nowcast GDP from monthly indicators
aligned <- nc_align(gdp, retail = retail, ip = ip)
result <- nc_bridge(target ~ retail + ip, data = aligned)
result$nowcast
GDP is published with a lag, typically 6 to 8 weeks after the quarter ends. But monthly indicators like retail sales, industrial production, and labour market data arrive much sooner. Nowcasting uses these higher-frequency series to estimate GDP growth in real time, before the official number appears.
The core challenge is the ragged edge: different indicators have different publication lags. Retail sales might be available through February, industrial production only through January, and employment through December, all at the same calendar date. A nowcasting model must handle this jagged pattern of data availability.
nowcast aligns mixed-frequency data, estimates bridge equations (the standard model at most central banks), and evaluates nowcast performance through pseudo-real-time backtesting.
| Feature | nowcast | bridgr | midasr | dfms |
|---|---|---|---|---|
| Bridge equations | Yes (with AR terms) | Yes | No | No |
| Mixed-frequency alignment | Yes | No | No | Yes |
| Ragged-edge diagnostics | Yes | No | No | Yes |
| Pseudo-real-time backtest | Yes | No | Yes (rolling) | No |
| Diebold-Mariano test | Yes (HLN corrected) | No | No | No |
| MIDAS | No | No | Yes | No |
| Dynamic factor models | No | No | No | Yes |
| Dependencies | 1 (cli) | 8+ (tidyverse) | 6+ | 3 |
nowcast provides bridge equations with integrated evaluation in a lightweight package. bridgr does bridge equations within the tidyverse ecosystem. midasr is a mature MIDAS implementation. dfms is a high-quality DFM package with a C++ backend. nowcast focuses on the evaluation side: pseudo-real-time backtesting and the HLN-corrected Diebold-Mariano test let you compare nowcasting specifications on the same data.
library(nowcast)
# Quarterly target (e.g. GDP growth)
gdp <- data.frame(
date = seq(as.Date("2015-01-01"), by = "quarter", length.out = 40),
value = rnorm(40, 0.5, 0.3)
)
# Monthly indicators (e.g. retail sales, industrial production)
retail <- data.frame(
date = seq(as.Date("2015-01-01"), by = "month", length.out = 120),
value = rnorm(120, 0.4, 0.5)
)
ip <- data.frame(
date = seq(as.Date("2015-01-01"), by = "month", length.out = 118), # ragged edge
value = rnorm(118, 0.3, 0.4)
)
# Align: monthly indicators are averaged to quarterly frequency
aligned <- nc_align(gdp, retail = retail, ip = ip)
aligned
#> ── Aligned Nowcasting Dataset ──
#> • Target: target (quarterly)
#> • Indicators: 2 (retail, ip)
#> • Periods: 40 (2015-01-01 to 2024-10-01)
# See the ragged edge
nc_ragged_edge(aligned)
# Bridge equation with AR(1) term (default)
result <- nc_bridge(target ~ retail + ip, data = aligned)
result
#> ── Nowcast (Bridge Equation) ──
#> • Nowcast: 0.4832
#> • SE: 0.3156
#> • 95% CI: [-0.1467, 1.1131]
#> • Target period: 2024-10-01
#> • R-squared: 0.1523 | Obs: 38
# Full summary with coefficients
summary(result)
# Static bridge equation (no AR terms)
nc_bridge(target ~ retail + ip, data = aligned, ar_order = 0)
# Expanding-window backtest: train on 1:i-1, nowcast i
bt <- nc_backtest(target ~ retail + ip, data = aligned, start = 20)
bt
#> ── Nowcast Backtest (bridge, expanding) ──
#> • Evaluations: 18
#> • RMSE: 0.2847
#> • MAE: 0.2312
#> • Bias: 0.0043
# Compare two specifications
bt_static <- nc_backtest(target ~ retail + ip, data = aligned,
start = 20, ar_order = 0)
nc_dm_test(bt$results$error, bt_static$results$error)
#> Diebold-Mariano (HLN): p = 0.42
# Plot actual vs nowcast
plot(bt)
| Category | Function | Description |
|---|---|---|
| Data | nc_align() |
Align mixed-frequency target and indicators |
| Data | nc_ragged_edge() |
Summarise data availability across series |
| Data | nc_aggregate() |
Temporal aggregation (monthly to quarterly/annual) |
| Data | nc_transform() |
Stationarity transforms (diff, log_diff, standardize) |
| Estimation | nc_bridge() |
Bridge equation with optional AR terms |
| Evaluation | nc_evaluate() |
RMSE, MAE, and bias |
| Evaluation | nc_dm_test() |
Diebold-Mariano test (HLN corrected) |
| Evaluation | nc_backtest() |
Pseudo-real-time expanding/rolling window evaluation |
| Utility | nc_available() |
List available methods |
| Utility | nc_compute() |
Generic dispatcher by method name |
| S3 |
print() / summary()
|
cli-formatted output for all objects |
| S3 | plot() |
Actual vs fitted/nowcast plots |
| S3 | predict() |
Predict from fitted nowcast model |
Bridge equations are the most widely used nowcasting method. They were developed at the ECB (Runstler and Sedillot 2003, Baffigi et al. 2004) and remain the standard model at most central banks and treasuries. The idea is simple: aggregate monthly indicators to the quarterly frequency, then regress the quarterly target on those aggregated indicators.
Following standard practice, nc_bridge() includes an autoregressive term by default (ar_order = 1) to capture GDP momentum. The model is:
$$y_t = \alpha + \phi y_{t-1} + \sum_i \beta_i \bar{x}_{i,t} + \varepsilon_t$$
where $\bar{x}_{i,t}$ is the within-quarter mean of monthly indicator $i$.
Prediction intervals come from predict.lm(..., interval = "prediction"), which accounts for both residual variance and coefficient estimation uncertainty, evaluated against the t distribution.
The nc_dm_test() function implements the Harvey, Leybourne, and Newbold (1997) modification of the Diebold-Mariano (1995) test. The HLN correction applies a finite-sample scaling factor and uses the t_{n-1} distribution rather than the standard normal. This matters at the sample sizes typical in nowcasting (20-60 quarters). The Bartlett (triangular) kernel is used for HAC variance estimation, which guarantees non-negative variance.
nc_backtest() performs pseudo-real-time evaluation on final revised data. At each step, the model sees only past data (expanding or rolling window) and produces a nowcast for the next period. This simulates real-time performance but does not account for data revisions. True real-time evaluation requires vintage data (e.g. from FRED's ALFRED database).
nc_ prefix. Short, distinctive, easy to type and autocomplete.nc_bridge() includes an AR(1) term by default. Set ar_order = 0 for a static specification.forecast::dm.test in R and statsmodels in Python).cli and stats. No tidyverse, no Rcpp, no external system libraries.ons, boe, fred, or any other data source.midasr. For DFMs, see dfms.nc_bridge() uses whatever the user provides in newdata. It does not forecast the missing months with AR/ARIMA. Central bank implementations typically do this, but it adds model-within-model complexity.result$details$dw_stat to help diagnose autocorrelation. For HAC-robust inference, extract the fitted model via result$model and use the sandwich package.| Package | Description |
|---|---|
ons |
UK Office for National Statistics data (high and low frequency indicators) |
boe |
Bank of England data (Bank Rate, financial conditions) |
fred |
Federal Reserve Economic Data (US monthly and quarterly indicators) |
readecb |
European Central Bank data (HICP, monetary aggregates) |
readoecd |
OECD cross-country macro indicators |
predictset |
Conformal prediction intervals around nowcast point estimates |
mpshock |
Monetary policy shock series |
inflationkit |
Inflation analysis (decomposition, persistence, Phillips curve) |
ivcheck |
IV diagnostics (for treatment-effect-style nowcasts) |
Found a bug or have a feature request? Please open an issue on GitHub.
nowcasting, GDP, macroeconomics, bridge equations, mixed frequency, economic forecasting, real-time data, ragged edge, time series, R package