twoStepSDFM: Two Step Sparse Dynamic Factor Model Estimator.

twoStepSDFMR Documentation

Two Step Sparse Dynamic Factor Model Estimator.

Description

Estimate a sparse dynamic factor model with measurement equation

\bm{x}_t = \bm{\Lambda} \bm{f}_{t} + \bm{\xi}_t,\quad \bm{\xi}_t \sim \mathcal{N}(\bm{0}, \bm{\Sigma}_{\xi}),

and transition equation

\bm{f}_t = \sum_{p=0}^P\bm{\Phi}_p \bm{f}_{t-p} + \bm{\epsilon}_t,\quad \bm{\epsilon}_t \sim \mathcal{N}(\bm{0}, \bm{\Sigma}_{f}).

using sparse principal components analysis and the Kalman Filter and Smoother according to \insertReffranjic2024nowcastingTwoStepSDFM.

Usage

twoStepSDFM(
  data,
  delay,
  selected,
  no_of_factors,
  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,
  fcast_horizon = 0,
  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 the same frequency.

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.

no_of_factors

Integer number of factors.

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

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.

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

Conversion threshold for the SPCA algorithm.

parallel

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

fcast_horizon

Integer number of additional Filter predictions into the future.

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 \insertCiteeigenwebTwoStepSDFM.

Details

The function performs a two-step estimation procedure for sparse dynamic factor models as described in \insertReffranjic2024nowcastingTwoStepSDFM. In the first step, the factor loading matrix is estimated using SPCA \insertCitezou2006sparseTwoStepSDFM. This will shrink some of the loadings towards or exactly to zero. In the second step the latent factors are estimated using the univariate representation of the Kalman Filter and Smoother \insertCitekoopman2000fastTwoStepSDFM.

The function takes three stopping criteria for the SPCA algorithm: selected, lasso_penalty, and max_no_steps. The argument weights allows specifying weights for the \ell_1 constraint. svd_method controls the decomposition method for internal SVDs. For a detailed description of these arguments and the SPCA step, see sparsePCA.

With respect to the univariate representation of the Kalman filter and smoother, decorr_errors indicates whether the data should be decorrelated internally prior to filtering and smoothing. jitter is added to the diagonal elements of the measurement variance–covariance matrix. For more details, see kalmanFilterSmoother.

For more information on the two-step estimation procedure see \insertReffranjic2024nowcastingTwoStepSDFM.

Value

An object of class SDFMFit with main components: #'

data

Original data object.

loading_matrix_estim

Numeric matrix of estimated factor loadings.

smoothed_factors

Object containing the SPCA factor estimates. The object inherits its class from data: If data is provided as zoo, factor_estim will be a zoo object. If data is provided as matrix, factor_estim will be a (no_of_factors\timesno_of_obs matrix.

smoothed_state_variance

(no_of_factors\times( no_of_factors * no_of_obs)) matrix, where each (no_of_factors \timesno_of_factors) block represents the smoother uncertainty at time pointt.

factor_var_lag_order

Integer order of the VAR process in the state equation.

error_var_cov_cholesky_factor

Numeric lower-triangular Cholesky factor of the estimated measurement error variance–covariance matrix.

llt_success_code

Integer indicating the status of the Cholesky factorization: 0 = LLT succeeded, -1 = LLT failed but LDLT succeeded, -2 = both failed and errors are treated as uncorrelated.

Author(s)

Domenic Franjic

References

\insertRef

koopman2000fastTwoStepSDFM

\insertRef

zou2006sparseTwoStepSDFM

\insertRef

eigenwebTwoStepSDFM

\insertRef

franjic2024nowcastingTwoStepSDFM

See Also

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

kalmanFilterSmoother: Routine for filtering and smoothing latent factors.

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

Examples

data(factor_model)
no_of_vars <- dim(factor_model$data)[2]
no_of_factors <- dim(factor_model$factors)[2]
sdfm_fit <- twoStepSDFM(data = factor_model$data, delay = factor_model$delay,
                        selected = rep(floor(0.5 * no_of_vars), no_of_factors),
                        no_of_factors = no_of_factors)
print(sdfm_fit)
sdfm_plots <- plot(sdfm_fit)
sdfm_plots$`Factor Time Series Plots`
sdfm_plots$`Loading Matrix Heatmap`
sdfm_plots$`Meas. Error Var.-Cov. Matrix Heatmap`
sdfm_plots$`Meas. Error Var.-Cov. Eigenvalue Plot`


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