How to Estimate a TVP Regression by Gibbs Sampling
Guide 2 of 3 in the series Time-Varying Parameters
Based on Chan and Jeliazkov (2009)
[ Journal Version | Working Paper | Code | Full guide on GitHub ]
We estimate the time-varying parameter (TVP) regression of How to Draw Time-Varying Regression Coefficients by Gibbs sampling, on the data of that guide. That guide holds the error variance σ2, the variances ωi2 of the random walks and the initial coefficients β0 at their true values. Here we estimate them along with the coefficients.
A Gibbs sampler draws the unknowns of a model in blocks and repeats. Each block is drawn from its distribution given the data and the current values of the other blocks. How to Estimate a State Space Model by Gibbs Sampling builds one for the local level model. Each iteration of our sampler draws the path of the coefficients as in the first guide, and then the parameters, each from a standard distribution.
The steps
- Split the Unknowns into Blocks
- Derive the Conditional Distributions
- Write the Loop
- Check the Chain

Figure 1: Top, the 20,000 draws of σ2, ω12 and ω22 kept after the burn-in, in the order the sampler makes them. Bottom, their histograms, the posterior densities computed on a grid without the sampler (solid lines; see How We Check It) and the true values (dashed lines).
Try it
In MATLAB, from the root of a copy of statespace-toolkit, run the script that prints every number and draws every figure of the guide:
run guides/tvp_gibbs/guide.m
In this series
Previous: How to Draw Time-Varying Regression Coefficients
Next: How to Tell Whether a Coefficient Varies over Time