Bayesian dynamic factor model estimation in R.
bdfm estimates dynamic factor models by simulation using the Durbin and Koopman (2012) disturbance smoother and returns estimated factors, predicted values of observables, posterior distributions for predicted values (optional), and forecast updates by series (optional). Maximum likelihood estimation via Watson and Engle (1983) is also supported. Input data may be noisy, have missing values, or “ragged edges” due to different start or end dates.
To install the development version:
remotes::install_github("srlanalytics/bdfm")
Estimate a model with one factor and two lags in the transition equation:
library(bdfm)
dta <- cbind(fdeaths, mdeaths)
m <- dfm(dta, forecast = 2)
Input data should be an object of class "ts"
. If the
tsbox package is installed, any ts-boxable
time series objects can be supplied, such as "xts"
, "zoo"
,
"timeSeries"
or "data.frame"
.
Extract the resulting series, using predict()
.
plot(predict(m))
Or have a look at the estimated factors, using factors()
:
plot(factors(m))
You can find details on estimation routines and derivations in the short book Practical Implementation of Factor Models.