dfms: Dynamic Factor Models for R

Status at rOpenSci Software Peer Review R-CMD-check CRAN status cran checks downloads per month downloads Codecov test coverage minimal R version status Project Status: Active – The project has reached a stable, usable state and is being actively developed.

NOTE: This package is under rOpenSci Statistical Software Peer Review. Peer review might result in changes to the API.


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

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. dfms with em.method = "BM" does allow mixed-frequency data but performs no specific adjustments for the frequency of the data1. dfms currently also does not allow residual autocorrelation in the estimation (i.e. it cannot estimate approximate factor models), but the addition of this feature is planned.

The package is currently not intended to fit more general forms of the state space model such as provided by MARSS, or advanced specifications of Dynamic Factor Models tailored to mixed-frequency nowcasting applications such as nowcasting and nowcastDFM. Such software could however benefit from the functions and methods provided in dfms, most notably dfms exports stationary Kalman Filters and Smoothers used in nowcasting applications, that are noticeably faster than the more general implementations provided by the FKF package.

Installation

# Development Version
remotes::install_github("SebKrantz/dfms")

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, em.method = "BM")

# '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)

  1. All series are weighted equally, and the prevalence of missing values in lower-frequency series downweights them. To remedy this lower frequency series could be included multiple times in the dataset e.g. include a quarterly series 3 times in a monthly dataset.↩︎