A C++-based R implementation of the two-step estimation procedure for a (linear Gaussian) Sparse Dynamic Factor Model (SDFM) as outlined in Franjic and Schweikert (2024).
The TwoStepSDFM package provides a fast implementation of the Kalman Filter and Smoother (hereinafter KFS, see Koopman and Durbin, 2000) to estimate factors in a mixed-frequency SDFM framework, explicitly accounting for cross-sectional correlation in the measurement error. The KFS is initialized using results from Sparse Principal Components Analysis (SPCA) by Zou and Hastie (2006) in a preliminary step. This approach generalizes the two-step estimator for approximate dynamic factor models by Giannone, Reichlin, and Small (2008) and Doz, Giannone, and Reichlin (2011). For more details see Franjic and Schweikert (2024).
simFM() function provides a flexible framework to simulate mixed-frequency data with ragged edges from an approximate DFM.noOfFactors() function uses the Onatski (2009) procedure to estimate the number of factors efficiently while providing good finite sample performance.twoStepSDFM() function provides a fast, memory-efficient, and convenient implementation of the two-step estimator outlined in Franjic and Schweikert (2024).crossVal() function provides a fast and parallel cross-validation wrapper to retrieve the optimal hyper-parameters using time-series cross-validation (Hyndman and Athanasopoulos 2018) with random hyper-parameter search (Bergstra and Bengio 2012).nowcast() function is a highly convenient prediction function for backcasts, nowcasts, and forecasts of multiple targets. It automatically takes care of all issues arising with mixed-frequency data and ragged edges.nowcast() function is also able to produce predictions of a dense DFM according to Giannone, Reichlin, and Small (2008). The function twoStepDenseDFM() additionally exposes an estimation procedure for the dense two-step estimator.sparsePCA() exposes the internal C++-backed SPCA routine in R. This provides access to a fast and memory-efficient SPCA estimation routine as implemented by Zou and Hastie (2020) in pure R.kalmanFilterSmoother() function exposes the internal C++-backed KFS routine.The package is available on CRAN and can be installed via install.packages("TwoStepSDFM"). If this turns out to be no longer possible, run the PackageBuilder.R file.
For the installation from source via the PackageBuilder.R file, the following is required:
C++ code into R (Eddelbuettel and François, 2011). Rcpp CRAN repositoryEigen linear algebra library into R (Bates and Eddelbuettel, 2013). RcppEigen CRAN repositoryFor a quick step-by-step user guide of the main features, see the package vignette.
License: GPL v3
(C) 2024-2026 Domenic Franjic
This project is licensed under the GNU General Public License v3.0. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
To Contribute:
If you have any questions or need assistance, please open an issue on the GitHub repository or contact us via email.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.