RATS 10.1
RATS 10.1

Procedures /

SURGIBBSSETUP Procedure

Home Page

← Previous Next →

@SURGibbsSetup pulls in a collection of procedures for setting up a Gibbs sampler for a (linear) SUR, such as a near-VAR. @SURGibbsSetup is done outside the simulation loop, while @SURGibbsDataInfo and @SURGibbsSigma are used inside it. A more complete explanation is provided in the "Bayesian Econometrics" e-course. Note that this requires inverting a matrix the size of the stacked coefficient vector, and so it might take a long time to do a substantial number of samples for a large model (say 1000+ total coefficients).

 

@SURGibbsSetup  model start end

 

examines the model, figures out the positions in the overall matrix of coefficients and computes the required cross product matrix of data over the range start to end.

 

 

@SURGibbsSigma(bdraw)

 

is a function which uses the input draw for the coefficients (bdraw) and returns the T x the covariance matrix of residuals at that set of coefficients.

 

 

@SURGibbsDataInfo  hdraw hdata hbdata

 

uses the current value of hdraw (draw for the residual precision matrix) to compute the data evidence on the precision of beta (returned as hdata) and that precision times the mean (returned as hbdata)

 

If

 

hxxprior is the prior residual precision x its degrees of freedom

hprior is the prior precision for the coefficients

bprior is the prior mean for the coefficients

wishdof is the posterior degrees of freedom for the residual precision, that is, the number of observations + degrees of freedom of the prior

 

then the calculation inside the loop will go something like:

 

compute covmat=SURGibbsSigma(bdraw)+hxxprior

compute hdraw=%ranwishartf(%decomp(inv(covmat)),wishdof)


@SURGibbsDataInfo hdraw hdata hbdata

compute bdraw=%ranmvposthb(hdata+hprior,hbdata+hprior*bprior)

 

where hdraw will be the draw for the precision (inverse covariance matrix) of the residuals and bdraw will be the draw for the stacked coefficient matrix. Typically, you will push bdraw back into the model for with %modelsetcoeffs(model,bdraw).

 

Example

This is part of the MONTESUR.RPF example (starting after the model has already been created into surmodel). This has a non-informative prior so the hprior in the above is a zero matrix and bprior doesn't matter. It draws the precision and coefficients, resets the coefficients for the model and does impulse responses. Note that the process naturally creates the precision of the residuals, which needs to be inverted to get the covariance matrix to determine the shocks.

 

@SURGibbsSetup surmodel

**********************************************

*

* Do a SUR to get a set of estimates to initialize the Gibbs sampler.

*

sur(model=surmodel)

compute ntotal=%nreg

compute bdraw=%beta

compute wishdof=%nobs

*

* For saving the IRF's

*

declare vect[rect] %%responses(ndraws)

*

infobox(action=define,progress,lower=-nburn,upper=ndraws) $

    "Gibbs Sampling"

do draw=-nburn,ndraws

   *

   * Compute covariance matrix of residuals at the current beta

   *

   compute covmat=SURGibbsSigma(bdraw)

   *

   * Do a draw for the precision matrix conditional on beta

   *

   compute hdraw=%ranwishartf(%decomp(inv(covmat)),wishdof)

   *

   * Compute the required information with the interaction between

   * the precision matrix and the data

   *

   @SURGibbsDataInfo hdraw hdata hbdata

   *

   * Draw coefficients given the precision matrix hdraw

   *

   compute bdraw=%ranmvposthb(hdata,hbdata)

   infobox(current=draw)

   if draw<=0

      next

   *

   * Do the bookkeeping here.

   *

   compute %modelsetcoeffs(surmodel,bdraw)

   compute sigmad=inv(hdraw)

   impulse(noprint,model=surmodel,factor=%decomp(sigmad),$

     steps=nsteps,flatten=%%responses(draw))

end do draw

infobox(action=remove)

@MCGraphIRF(model=surmodel,center=median,page=all)

 


Copyright © 2025 Thomas A. Doan