Download GNUMCSim: A Monte Carlo Simulation Program

Transcript
Chapter 6: Running Simulations
49
file). A Level section starts with the corresponding keyword and is enclosed in curly braces
(’{}’). It can include any number of sub-levels or Simulations sections. Simulations
(where the data are specified) form the lowest level of the hierarchy (see [Simulation sections], page 45). In terms of structure, Simulation sections behave like Level sections
(in particular with regard to "cloning" of random variables, see below) except that they
cannot include further levels. There must be one and only one top Level and at most 10
nested sub-levels in the hierarchy. This limit of 10 can be increased (up to 255) by changing
MAX LEVELS in the header file sim.h and re-installing GNU MCSim.
A Level can specify or change the sampling distribution of any model parameter properly
defined in the global section of the structural model description file. These distribution
specifications apply to all sub-levels of the Level where they take place. For example:
MCMC("samp.out", "", "", 1, 1, 1, 1, 1); # we are in an MCMC context
Level { # this is the top level
Distrib(A, Uniform, 0, 1);
Likelihood(Data(y), Normal, Prediction(y), 1);
Level { # sub-level 1
Distrib(A, Normal, A, 1);
Simulation { ... } # simulation 1
Simulation { ... } # simulation 2
} # End sub-level 1
} # End top, end file
A Level can also make simple assignments to any model parameter (see Section 6.2.1
[General input file syntax], page 35). So, for example, in an simulation, the parameter A
could be modified with:
A = 2.0;
This overrides any previously assigned values for the specified parameter, even if randomly sampled, and applies to the sub-levels of the Level where it take place.
An important concept to grasp here is that of parameter "cloning". Cloning automatically creates, using templates, as many new parameters as you need in your multilevel
model. One of the characteristic feature of multilevel models is the same parameters appear at several levels. For example, in a random effect model, a parameter (e.g., size) will
be assumed to be randomly distributed in a population of individuals. If you have 100 individuals in your database, your model will have to deal with 100 individual size parameters
and an average size. To spare you the tedium of defining the same distribution for many
parameters, GNU MCSim creates an appropriate number of parameters for your model on
the basis of its level structure. Assume that you have specified a distribution for a parameter A at a given level (that we label L1 for clarity). GNU MCSim will automatically
create new parameters ("clones") with the same distribution as A to match the number of
immediate sub-levels in L1. For example, if there are three sub-levels included in L1, GNU
MCSim creates two clones to form a total of three instances of A (the original and its two
clones). This convention saves a lot writing and effort in the long run.
In the sample of code given above, the parameter A, defined at the top level, will be
simply moved to sub-level 1 (cloning is not necessary since there is only on sub-level directly