https://github.com/sebkrantz/dfms
Dynamic Factor Models for R
https://github.com/sebkrantz/dfms
dynamic-factor-models rstats time-series
Last synced: about 1 year ago
JSON representation
Dynamic Factor Models for R
- Host: GitHub
- URL: https://github.com/sebkrantz/dfms
- Owner: SebKrantz
- License: gpl-3.0
- Created: 2021-08-25T09:04:15.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-22T10:53:42.000Z (about 1 year ago)
- Last Synced: 2025-04-10T03:53:51.286Z (about 1 year ago)
- Topics: dynamic-factor-models, rstats, time-series
- Language: R
- Homepage: https://sebkrantz.github.io/dfms/
- Size: 26.1 MB
- Stars: 33
- Watchers: 2
- Forks: 9
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: NEWS.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Codemeta: codemeta.json
Awesome Lists containing this project
README
# **dfms**: Dynamic Factor Models for R
[](https://github.com/ropensci/software-review/issues/556)
[](https://github.com/SebKrantz/dfms/actions)
[](https://sebkrantz.r-universe.dev)
[](https://cran.r-project.org/package=dfms)
[](https://cran.r-project.org/web/checks/check_results_dfms.html)


[](https://app.codecov.io/gh/SebKrantz/dfms?branch=main)
[](https://cran.r-project.org/)
[](https://CRAN.R-project.org/package=dfms)
*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.
- 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.
- 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.
The default is `em.method = "auto"`, which chooses `"BM"` following Banbura & Modugno (2014) with missing data or mixed frequency, and `"DGR"` following Doz, Giannone & Reichlin (2012) otherwise. 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 methods support missing data, but `em.method = "DGR"` does not model them in EM iterations.
### 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 forecasting. The implementation is based on efficient C++ code, making *dfms* orders of magnitude faster than packages that can be used to fit dynamic factor models such as [*MARSS*](), or [*nowcasting*]() and [*nowcastDFM*]() geared to mixed-frequency nowcasting applications - supporting blocking of variables into different groups for which factors are to be estimated and evaluation of news content. For large-scale nowcasting models the [`DynamicFactorMQ`](https://www.statsmodels.org/dev/generated/statsmodels.tsa.statespace.dynamic_factor_mq.DynamicFactorMQ.html) class in the `statsmodels` Python library is probably the most robust implementation - see the [example](http://www.chadfulton.com/topics/statespace_large_dynamic_factor_models.html) by Chad Fulton.
The *dfms* package is not intended to fit more general forms of the state space model like [*MARSS*]().
### Installation
```r
# CRAN
install.packages("dfms")
# Development Version
install.packages('dfms', repos = c('https://sebkrantz.r-universe.dev', 'https://cloud.r-project.org'))
```
### Usage Example
```r
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)
```