Package: dfms 0.2.2

Sebastian Krantz

dfms: Dynamic Factor Models

Efficient estimation of Dynamic Factor Models using the Expectation Maximization (EM) algorithm or Two-Step (2S) estimation, supporting datasets with missing data. The estimation options follow advances in the econometric literature: either running the Kalman Filter and Smoother once with initial values from PCA - 2S estimation as in Doz, Giannone and Reichlin (2011) <doi:10.1016/j.jeconom.2011.02.012> - or via iterated Kalman Filtering and Smoothing until EM convergence - following Doz, Giannone and Reichlin (2012) <doi:10.1162/REST_a_00225> - or using the adapted EM algorithm of Banbura and Modugno (2014) <doi:10.1002/jae.2306>, allowing arbitrary patterns of missing data. The implementation makes heavy use of the 'Armadillo' 'C++' library and the 'collapse' package, providing for particularly speedy estimation. A comprehensive set of methods supports interpretation and visualization of the model as well as forecasting. Information criteria to choose the number of factors are also provided - following Bai and Ng (2002) <doi:10.1111/1468-0262.00273>.

Authors:Sebastian Krantz [aut, cre], Rytis Bagdziunas [aut]

dfms_0.2.2.tar.gz
dfms_0.2.2.tar.gz(r-4.5-noble)dfms_0.2.2.tar.gz(r-4.4-noble)
dfms_0.2.2.tgz(r-4.4-emscripten)dfms_0.2.2.tgz(r-4.3-emscripten)
dfms.pdf |dfms.html
dfms/json (API)
NEWS

# Install 'dfms' in R:
install.packages('dfms', repos = 'https://cloud.r-project.org')

Bug tracker:https://github.com/sebkrantz/dfms/issues1 issues

Pkgdown site:https://sebkrantz.github.io

Uses libs:
  • openblas– Optimized BLAS
  • c++– GNU Standard C++ Library v3
Datasets:
  • BM14_M - Euro Area Macroeconomic Data from Banbura and Modugno 2014
  • BM14_Models - Euro Area Macroeconomic Data from Banbura and Modugno 2014
  • BM14_Q - Euro Area Macroeconomic Data from Banbura and Modugno 2014

On CRAN:

Conda:

openblascpp

3.00 score 1 stars 531 downloads 10 exports 3 dependencies

Last updated 10 months agofrom:d4387f7eba. Checks:1 OK, 2 NOTE. Indexed: no.

TargetResultLatest binary
Doc / VignettesOKMar 07 2025
R-4.5-linux-x86_64NOTEMar 07 2025
R-4.4-linux-x86_64NOTEMar 07 2025

Exports:.VARainvapinvDFMem_convergedFISICrSKFSKFStsnarmimp

Dependencies:collapseRcppRcppArmadillo

Dynamic Factor Models: A Very Short Introduction

Rendered fromdynamic_factor_models.Rnwusingutils::Sweaveon Mar 07 2025.

Last update: 2023-03-31
Started: 2023-03-31

Introduction to dfms

Rendered fromintroduction.Rmdusingknitr::rmarkdownon Mar 07 2025.

Last update: 2023-03-31
Started: 2022-10-12

Citation

To cite package ‘dfms’ in publications use:

Krantz S, Bagdziunas R (2024). dfms: Dynamic Factor Models. R package version 0.2.2, https://CRAN.R-project.org/package=dfms.

Corresponding BibTeX entry:

  @Manual{,
    title = {dfms: Dynamic Factor Models},
    author = {Sebastian Krantz and Rytis Bagdziunas},
    year = {2024},
    note = {R package version 0.2.2},
    url = {https://CRAN.R-project.org/package=dfms},
  }

Readme and manuals

dfms: Dynamic Factor Models for Rdfms

dfms provides efficient estimation of Dynamic Factor Models via the EM Algorithm. Estimation can be done in 3 different ways following:

  • Doz, C., Giannone, D., & Reichlin, L. (2011). A two-step estimator for large approximate dynamic factor models based on Kalman filtering. Journal of Econometrics, 164(1), 188-205. doi:10.1016/j.jeconom.2011.02.012

  • Doz, C., Giannone, D., & Reichlin, L. (2012). A quasi-maximum likelihood approach for large, approximate dynamic factor models. Review of economics and statistics, 94(4), 1014-1024. doi:10.1162/REST_a_00225

  • Banbura, M., & Modugno, M. (2014). Maximum likelihood estimation of factor models on datasets with arbitrary pattern of missing data. Journal of Applied Econometrics, 29(1), 133-160. doi:10.1002/jae.2306

The default is em.method = "auto", which chooses "DGR" following Doz, Giannone & Reichlin (2012) if there are no missing values in the data, and "BM" following Banbura & Modugno (2014) with missing data. Using em.method = "none" generates Two-Step estimates following Doz, Giannone & Reichlin (2011). This is extremely efficient on bigger datasets. PCA and Two-Step estimates are also reported in EM-based methods.

All 3 estimation methods support missing data, with various preprocessing options, but em.method = "DGR" does not account for them in the EM iterations, and should only be used if a few values are missing at random. For all other cases em.method = "BM" or em.method = "none" is the way to go.

Comparison with Other R Packages

dfms is intended to provide a simple, numerically robust, and computationally efficient baseline implementation of (linear Gaussian) Dynamic Factor Models for R, allowing straightforward application to various contexts such as time series dimensionality reduction and multivariate forecasting. The implementation is based on efficient C++ code, making dfms orders of magnitude faster than packages such as MARSS that can be used to fit dynamic factor models, or packages like nowcasting and nowcastDFM, which fit dynamic factor models specific to mixed-frequency nowcasting applications. The latter two packages additionally support blocking of variables into different groups for which factors are to be estimated, and EM adjustments for variables at different frequencies. The package is currently not intended to fit more general forms of the state space model such as provided by MARSS.

Installation
# CRAN
install.packages("dfms")

# Development Version
install.packages('dfms', repos = c('https://sebkrantz.r-universe.dev', 'https://cloud.r-project.org'))

Usage Example
library(dfms)

# Fit DFM with 6 factors and 3 lags in the transition equation
mod = DFM(diff(BM14_M), r = 6, p = 3) 

# 'dfm' methods
summary(mod)
plot(mod)
as.data.frame(mod)

# Forecasting 20 periods ahead
fc = predict(mod, h = 20)

# 'dfm_forecast' methods
print(fc)
plot(fc)
as.data.frame(fc)

Help Manual

Help pageTopics
(Fast) Barebones Vector-Autoregression.VAR
Armadillo's Inverse Functionsainv apinv
Extract Factor Estimates in a Data Frameas.data.frame.dfm
Euro Area Macroeconomic Data from Banbura and Modugno 2014BM14_M BM14_Models BM14_Q
Estimate a Dynamic Factor ModelDFM
Convergence Test for EM-Algorithmem_converged
(Fast) Fixed-Interval Smoother (Kalman Smoother)FIS
Information Criteria to Determine the Number of Factors (r)ICr plot.ICr print.ICr screeplot.ICr
Plot DFMplot.dfm screeplot.dfm
DFM Forecastsas.data.frame.dfm_forecast plot.dfm_forecast predict.dfm print.dfm_forecast
DFM Residuals and Fitted Valuesfitted.dfm resid.dfm residuals.dfm
(Fast) Stationary Kalman FilterSKF
(Fast) Stationary Kalman Filter and SmootherSKFS
DFM Summary Methodsprint.dfm print.dfm_summary summary.dfm
Remove and Impute Missing Values in a Multivariate Time Seriestsnarmimp