How-To Guides
Each guide shows how to turn a model's equations into working MATLAB code with the core functions of bvar-toolkit and statespace-toolkit, one step at a time, on a small example with generated data. A script with each guide reproduces every number and figure on its page. The guides come in series, and within a series each guide builds on the one before. These pages summarize the guides; the full guides on GitHub give the derivations, the code and the checks. The tutorials answer empirical questions with the models of published papers.
Series:
- Getting Started with the Precision Sampler (3 guides)
- Getting Started with Bayesian VARs (4 guides)
- Forecasting with a VAR (4 guides)
Newest series: Forecasting with a VAR (October 2026)
Getting Started with the Precision Sampler
The three guides use the local level model on the same generated data.
- How to Draw the States of an Unobserved Components Model
Draw the whole path of the states at once with the precision sampler. (statespace-toolkit) - How to Estimate a State Space Model by Gibbs Sampling
Draw the parameters and the states in turn, and check the chain. (statespace-toolkit) - How to Compute the Integrated Likelihood of a State Space Model
Integrate the states out of the likelihood, and draw the parameters without them. (statespace-toolkit)
Getting Started with Bayesian VARs
The guides use the same generated VAR(2) of three variables.
- How to Stack the Equations of a VAR
Stack the equations in matrix form and as one long regression. (bvar-toolkit) - How to Draw the VAR Coefficients under the Minnesota Prior
Get posterior draws of the VAR coefficients. (bvar-toolkit) - How to Estimate a VAR by Gibbs Sampling
Draw the coefficients and the error covariance matrix in turn, and check the chain. (bvar-toolkit) - How to Choose the Shrinkage of a VAR by the Marginal Likelihood
Choose the shrinkage and the lag length by the closed-form marginal likelihood. (bvar-toolkit)
Forecasting with a VAR
The guides use data simulated from a VAR(4) fitted to US real GDP growth, PCE inflation and the unemployment rate, 1960Q1 to 2019Q4.
- How to Simulate Data from an Estimated VAR
Simulate data from a VAR fitted to US GDP growth, inflation and unemployment. (bvar-toolkit) - How to Forecast with a Bayesian VAR
Forecast from posterior draws, and compare with the true model's forecasts. (bvar-toolkit) - How to Evaluate Forecasts Out of Sample
Score forecasts made at each quarter with the data of the time. (bvar-toolkit) - How to Choose the Lag Length and the Shrinkage for Forecasting
Choose the lag length and the shrinkage by the marginal likelihood at each forecast origin. (bvar-toolkit)