bayesdfa implements Bayesian Dynamic Factor Analysis (DFA) with Stan.

You can install the development version of the package with:

# install.packages("devtools")


We’ve put together several vignettes for using the bayesdfa package.
Combining data
Compositional models
Including covariates
Estimating process variance
DFA for big data

Additional examples can be found in the course that Eli Holmes, Mark Scheuerell, and Eric Ward teach at the University of Washington:
Course webpage
Lab book


For DFA models in general, we recommend citing the MARSS package or user guide.

    title = {{MARSS}: multivariate autoregressive state-space models for analyzing time-series data},
    volume = {4},
    url = {},
    number = {1},
    journal = {R Journal},
    author = {Holmes, E.E. and Ward, Eric J. and Wills, K.},
    year = {2012},
    pages = {11--19}

    title = {{MARSS}: Analysis of multivariate timeseries using the MARSS package},
    url = {},
    author = {Holmes, E.E. and Scheurell, M.D. and Ward, Eric J.},
    year = {2020},

For citing the bayesdfa package using Bayesian estimation, or models with extra features (such as extremes), cite

  author = {Eric J. Ward and Sean C. Anderson and Luis A. Damiano and
          Mary E. Hunsicker and Michael A. Litzow},
  title = {{Modeling regimes with extremes: the bayesdfa package for
          identifying and forecasting common trends and anomalies in
          multivariate time-series data}},
  year = {2019},
  journal = {{The R Journal}},
  doi = {10.32614/RJ-2019-007},
  url = {}


The ‘bayesdfa’ models were presented to the PFMC’s SSC in November 2017 and have been included in the 2018 California Current Integrated Ecosystem Report,


The ‘bayesdfa’ package was funded by a NOAA Fisheries and the Environment (FATE) grant on early warning indicators, led by Mary Hunsicker and Mike Litzow.

NOAA Disclaimer

This repository is a scientific product and is not official communication of the National Oceanic and Atmospheric Administration, or the United States Department of Commerce. All NOAA GitHub project code is provided on an ‘as is’ basis and the user assumes responsibility for its use. Any claims against the Department of Commerce or Department of Commerce bureaus stemming from the use of this GitHub project will be governed by all applicable Federal law. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by the Department of Commerce. The Department of Commerce seal and logo, or the seal and logo of a DOC bureau, shall not be used in any manner to imply endorsement of any commercial product or activity by DOC or the United States Government.

NOAA Fisheries

U.S. Department of Commerce | National Oceanographic and Atmospheric Administration | NOAA Fisheries