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:

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.

  1. 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)
  2. How to Estimate a State Space Model by Gibbs Sampling
    Draw the parameters and the states in turn, and check the chain. (statespace-toolkit)
  3. 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.

  1. How to Stack the Equations of a VAR
    Stack the equations in matrix form and as one long regression. (bvar-toolkit)
  2. How to Draw the VAR Coefficients under the Minnesota Prior
    Get posterior draws of the VAR coefficients. (bvar-toolkit)
  3. How to Estimate a VAR by Gibbs Sampling
    Draw the coefficients and the error covariance matrix in turn, and check the chain. (bvar-toolkit)
  4. 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.

  1. How to Simulate Data from an Estimated VAR
    Simulate data from a VAR fitted to US GDP growth, inflation and unemployment. (bvar-toolkit)
  2. How to Forecast with a Bayesian VAR
    Forecast from posterior draws, and compare with the true model's forecasts. (bvar-toolkit)
  3. How to Evaluate Forecasts Out of Sample
    Score forecasts made at each quarter with the data of the time. (bvar-toolkit)
  4. 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)