RATS 10.1
RATS 10.1

Wizards /

Monte Carlo/Gibbs Loop Pseudo-Code Generator

Home Page

← Previous Next →

The Monte Carlo/Gibbs Loop Pseudo-Code Generator is brought up by the Help—Pseudo-Code Generator-Monte Carlo/Gibbs Loop... operation. It generates pseudo-code for several different types of simulation loops. Note well that these are designed only to create the common instructions for such loop types, to help you organize this. The actual simulation and bookkeeping code will have to be added to give them content.
 

The simplest loop type is for "Simple Monte Carlo", which is for an analysis where you can generate draws independently of each other. This requires you to choose a Loop Variable Name (which will be the index variable on the controlling DO loop), a Draw Limit Variable Name and the numerical value for the draw limit. (Here DRAW, NDRAWS and 100). This is intentionally set to use only a fairly small number of draws—you can obviously override that now, though we would recommend that you start small and only increase it when you're sure that the rest of the program is working properly. See the pseudo-code section for more on this, as it works through an example of adding content to this type of loop.
 

This and the other types of loops allow you to add a progress bar (with an optional title). To include that, check the Include Progress Bar box and add a Title if you want. At the default of 100 draws the progress bar will probably do nothing more than flash, but when you move to a production level, you might find it handy.


 


 

The next loop type is "Gibbs Sampling". This has the same three elements as the simpler loop, but adds the Burn Limit Variable Name and the corresponding number of burn-in draws (here NBURN and 100). The "draw" limit is interpreted as the number of draws that you want to keep. As the loop is set up, this actually runs through one extra burn-in draw, as the value of DRAW runs from -100 to +100, with the good draws starting when DRAW=1. (This makes the looping much simpler and more obvious). The inside of the loop is the following:

 

   *

   * Draw each subset of parameters conditional on the others

   *

   IF DRAW<=0

      NEXT

   *

   * Do bookkeeping here. Save results for entry DRAW

   *
 

which skips the "bookkeeping" section until the value of DRAW goes positive.


 


 


There are two loop types of Metropolis-Hastings loops (or Metropolis-within-Gibbs). One is for "Random Walk Metropolis", the other from "Independence Chain Metropolis". (There are other, more complicated forms, which aren't included). These have exactly the same fields in the dialog, and generate fairly similar loop structures—Independence Chain requires a few extra steps since the probability of generating a candidate enters into the acceptance probability). These add one extra field to the dialog compared to the Gibbs sampling, which is the Acceptance Count Variable (here ACCEPT). This keeps track of the number of accepted new candidates (or "jumps").

 

 


 


Copyright © 2025 Thomas A. Doan