knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-" )
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)
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.
MARSS, dynfactoR : Offer maximum likelihood estimation only
greta : Uses Hamiltonian Monte Carlo simulation find posterior distributions of model parameters for whatever model the user specifies. It looks superb, but being general purpose it is much more difficult to implement DFMs than with bdfm.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.