Statsmodels
, a Python library for statistical and econometric analysis,
has traditionally focused on frequentist inference, including in its
models for time series data. This paper and Poster illustrates the powerful
features for Bayesian inference of time series models that exist in
statsmodels
, with applications to model fitting, forecasting, time series
decomposition, data simulation, and impulse response functions.
Suggestions for reading and using this Poster
Our suggestion for using this Poster is as follows.
- The most accessible place to start is the paper. It is relatively short, and guides the reader through the main concepts and key code segments.
- The poster itself is a Jupyter notebook,
Poster.ipynb
, and it can be (a) run to reproduce the analysis and figures in the paper, and (b) copied and modified to apply these tools and concepts to whatever project the reader wishes! - For readers who wish to go further, additional resources on Bayesian analysis of time series models in Statsmodels are listed below.
More details about each of these follow:
1. Paper
Included in this repository is a draft of the paper
Bayesian Estimation and Forecasting of Time Series in Statsmodels.pdf
that is
forthcoming in the Proceedings of the 21st Python in Science Conference (SciPy
2022). This paper introduces the time series models included in Statsmodels and
shows how to estimate their parameters using Bayesian methods. It also briefly
describes the relationship to other popular Python libraries for Bayesian
inference, including PyMC, PyStan, and ArviZ.
2. Poster
The paper also provides code samples for several applications that include
parameter estimation, forecasting, and causal inference. To keep the paper
readable, the code included inline is only brief, but the Poster included in
this repostory, Poster.ipynb
, is a Jupyter notebook that contains the complete
code for performing the Bayesian analysis in the paper.
3. Additional resources for Bayesian analysis of time series models in Statsmodels
- Autoregressive moving average (ARMA) model.
This Jupyter notebook shows how to estimate the parameters of an
SARIMAX
model (which is already built-in to Statsmodels) using Bayesian methods. - Stochastic volatility model. This Jupyter notebook shows (a) how to create a custom state space model that represents a stochastic volatility process, (b) how to apply it to an exchange rate time series, and (c) how to then estimate the parameters using Bayesian methods.
- Time-Varying Parameter Vector Autoregression (TVP-VAR) model. This Jupyter notebook shows (a) how to create a custom state space model that represents a TVP-VAR model, and (b) how to then estimate the parameters using Bayesian methods.
- Dynamic stochastic general equilibrium (DSGE) economic model. This Jupyter notebook shows how to set up and solve a simple Real Business Cycle economic model, and how to estimate its structural parameters using Bayesian methods.