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. The guides of bvar-toolkit also have Python versions, in bvar-toolkit-python.
Series:
- Getting Started with the Precision Sampler (3 guides)
- Time-Varying Parameters (3 guides)
- Stochastic Volatility (4 guides)
- Getting Started with Bayesian VARs (4 guides)
- Forecasting with a VAR (4 guides)
Newest series: Stochastic Volatility (November 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)
Time-Varying Parameters
The three guides use a regression whose coefficients follow random walks, on generated data.
- How to Draw Time-Varying Regression Coefficients
Stack the regression over time and draw the whole path of the coefficients at once. (statespace-toolkit) - How to Estimate a TVP Regression by Gibbs Sampling
Draw the variances and the initial coefficients along with the coefficients, and check the chain. (statespace-toolkit) - How to Tell Whether a Coefficient Varies over Time
Compare models whose coefficients vary or stay constant by their marginal likelihoods. (statespace-toolkit)
Stochastic Volatility
The four guides use two stochastic volatility models, one with Gaussian errors and one with Student-t errors, on generated data. In both, the log-volatility follows a stationary AR(1) process.
- How to Draw the Log-Volatilities of a Stochastic Volatility Model
Draw the whole path of the log-volatilities by the auxiliary mixture sampler, and from their exact conditional distribution. (statespace-toolkit) - How to Estimate a Stochastic Volatility Model by Gibbs Sampling
Draw the mean and the parameters of the log-volatility along with it, and check the chain. (statespace-toolkit) - How to Add Student-t Errors to a Stochastic Volatility Model
Replace the Gaussian errors with Student-t errors, so that outliers have less effect on the estimated volatility. (statespace-toolkit) - How to Compare Stochastic Volatility Models by the Marginal Likelihood
Compare the two stochastic volatility models and a constant-variance model by their marginal likelihoods. (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)