nowcast: Predict Mixed-Frequency Data via Dynamic Factor Models

View source: R/Nowcast.R

nowcastR Documentation

Predict Mixed-Frequency Data via Dynamic Factor Models

Description

Backcast, nowcast, and forecast quarterly target variables via a sparse/dense DFM using additional monthly data with ragged edges. Forecasts are produced using all quarterly targets and a quarterly representation of latent monthly factors \insertCiteMariano2003new_coincidentTwoStepSDFM. Final predictions are computed via equally weighted forecast averaging of ARDL models \insertCitemarcellino2010factorTwoStepSDFM for each of the targets and quarterfied factors.

Usage

nowcast(
  data,
  variables_of_interest,
  max_fcast_horizon,
  delay,
  selected,
  frequency,
  no_of_factors,
  sparse = TRUE,
  max_factor_lag_order = 10,
  lag_estim_criterion = "BIC",
  decorr_errors = TRUE,
  ridge_penalty = 1e-06,
  lasso_penalty = NULL,
  max_iterations = 1000,
  max_no_steps = NULL,
  weights = NULL,
  comp_null = 1e-15,
  spca_conv_crit = 1e-04,
  parallel = FALSE,
  max_ar_lag_order = 5,
  max_predictor_lag_order = 5,
  jitter = 1e-08,
  svd_method = "precise"
)

Arguments

data

Numeric (no_of_vars \times no_of_obs) matrix of data or zoo/xts object sampled at mixed frequencies (quarterly and monthly).

variables_of_interest

Integer vector indicating the index of all target variables.

max_fcast_horizon

Maximum forecasting horizon of all targets.

delay

Integer vector of variable delays, measured as the number of months since the latest available observation.

selected

Integer vector of the number of selected variables for each factor.

frequency

Integer vector of frequencies of the variables in the data set (currently supported: 12 for monthly and 4 for quarterly data).

no_of_factors

Integer number of factors.

sparse

Logical, if TRUE (default) a sparse DFM is used to estimate the model parameters and latent factors (see twoStepSDFM). Else, a dense DFM is used (see twoStepDenseDFM).

max_factor_lag_order

Integer maximum order of the VAR process in the transition equation.

lag_estim_criterion

Information criterion used for the estimation of the factor VAR order ("BIC" (default), "AIC", "HIC").

decorr_errors

Logical, whether or not the errors should be decorrelated.

ridge_penalty

Numeric ridge penalty.

lasso_penalty

Numeric vector, lasso penalties for each factor (set to NULL to disable as stopping criterion).

max_iterations

Integer maximum number of iterations of the SPCA algorithm.

max_no_steps

Integer number of LARS steps (set to NULL to disable as stopping criterion).

weights

Numeric vector, weights for each variable weighing the \ell_1 size constraint.

comp_null

Numeric computational zero.

spca_conv_crit

Numeric conversion criterion for the SPCA algorithm.

parallel

Logical, whether or not to use Eigen's internal parallel matrix operations.

max_ar_lag_order

Integer maximum number of lags of the target variable included in the final ARDL prediction routine.

max_predictor_lag_order

Integer maximum number of lags of the predictors included in the final ARDL prediction routine.

jitter

Numerical jitter for stability of internal solver algorithms. The jitter is added to the diagonal entries of the variance covariance matrix of the measurement errors.

svd_method

Either "fast" or "precise". Option "fast" uses Eigen's BDCSVD divide and conquer method for the computation of the singular values. Option "precise" (default) implements the slower, but numerically more stable JacobiSVD method.

Details

This function serves as a prediction wrapper for the twoStepDenseDFM and twoStepSDFM functions. data should be a mixed-frequency data set. Currently, only monthly and quarterly data are supported. With respect to the quarterly data, the function expects the realization of the quarterly observations to occur in the last month of the quarter. Indicate quarterly and monthly variables via frequency by setting the corresponding element of frequency to 4 for quarterly and to 12 for monthly data.

This function is only able to compute predictions for quarterly variables. To impute the ragged edges of the monthly observations, and potentially compute additional predictions for the monthly variables, call predict on the SDFMFit object returned by twoStepDenseDFM / twoStepSDFM (see predict.SDFMFit).

max_fcast_horizon sets the maximum number of forecasts predicted starting from the final observation of the data set. For each target, the number of backcasts and whether or not a nowcast should be computed is determined internally. This is done in such a way that every missing quarterly observation of the targets is predicted.

max_ar_lag_order governs the maximum number of lags of the current target used to predict said target in each ARDL model. max_predictor_lag_order governs the maximum number of lags of each additional quarterly predictor, including other potential targets and the aggregated factors, used to predict any given target in each ARDL model. The actual number of lags is internally estimated using the BIC. Setting max_ar_lag_order = 0 disables the use of target lags in its own prediction function.

sparse toggles between a sparse DFM and a dense DFM. If sparse = FALSE, all SPCA stopping criteria and other parameters passed to the sparse estimation routine are ignored (for details on these parameters see twoStepDenseDFM). Parameters governing the Kalman Filter and Smoother are passed directly to twoStepDenseDFM / twoStepSDFM. For details see the corresponding help pages.

Value

The nowcast function returns named list containing the following objects:

Forecasts

Numeric matrix of the target variables and their respective backcasts, nowcasts, and/or forecasts.

SDFM Fit

An SDFMFit object holding the estimates of the model parameters and the latent factors (see twoStepSDFM or twoStepDenseDFM).

Author(s)

Domenic Franjic

References

\insertRef

Mariano2003new_coincidentTwoStepSDFM

\insertRef

marcellino2010factorTwoStepSDFM

\insertRef

franjic2024nowcastingTwoStepSDFM

See Also

sparsePCA: Routine for fitting estimating a sparse factor loading matrix.

kalmanFilterSmoother: Routine for filtering and smoothing latent factors.

twoStepSDFM: Two-step estimation routine for a sparse dynamic factor model.

twoStepDenseDFM: Two-step estimation routine for a dense dynamic factor model.

Examples

data(mixed_freq_factor_model)
no_of_vars <- dim(mixed_freq_factor_model$data)[2]
no_of_factors <- dim(mixed_freq_factor_model$factors)[2]
sparse_nowcast <- nowcast(data = mixed_freq_factor_model$data, variables_of_interest = c(1, 2),
                          max_fcast_horizon = 4, delay = mixed_freq_factor_model$delay,
                          selected = rep(floor(0.5 * no_of_vars), no_of_factors), 
                          frequency = mixed_freq_factor_model$frequency, 
                          no_of_factors = no_of_factors, sparse = TRUE)
print(sparse_nowcast)
dense_nowcast <- nowcast(data = mixed_freq_factor_model$data, variables_of_interest = c(1, 2),
                         max_fcast_horizon = 4, delay = mixed_freq_factor_model$delay,
                         selected = NULL, frequency = mixed_freq_factor_model$frequency, 
                         no_of_factors = no_of_factors, sparse = FALSE)
sparse_plots <- plot(sparse_nowcast)
sparse_plots$`Single Pred. Fcast Density Plots Series 1`


TwoStepSDFM documentation built on May 19, 2026, 9:07 a.m.