Description Usage Arguments Details Value To Do
This function performs a basic Metropolis sampling of a user-supplied log-posterior function. The sampling is done in batches, with the batch means returned as the output. Setting the batch length to 1 will produce unbatched samples.
1 2 |
lpost |
Log-posterior function |
p0 |
Starting parameters for sampling, OR a |
nsamp |
Number of batches to run |
batchlen |
Number of samples per batch |
scale |
MC step scaler; this will be multiplied by a vector of standard
normal deviates to get the proposal step. Optional if a |
debug |
Flag to turn on additional debugging information. |
lp0 |
Log-posterior for the starting parameters (p0). If not supplied it will be calculated automatically. |
The output metrosamp
structure will be a list with the following elements:
Matrix (nsamp x nparam) of parameter samples
Vector (nsamp) of log-posterior values for the samples
Probability of accepting a proposal, averaged across all samples
Last parameter set. Can be used to continue sampling where the last run left off.
Scale factor used in the calculation. Also useful for continuing a run.
If the debug
flag is set, the output will have some additional
elements that can be used to diagnose the sampling procedure. If batch
sampling is in use, then most of these will pertain to the last
proposal evaluated in each batch. Intermediate proposals within a batch are
not returned. Therefore, when debugging proposals, it is best to use a batch
length of 1.
The proposal parameters evaluated by the sampler.
Log-posterior for the proposals. The same notes apply as to
the proposals
entry.
Flag indicating whether each proposal was accepted.
A run can be continued by passing the metrosamp
structure from the
previous run as the p0
argument. If this is done, then the
scale
parameter may be omitted, and the new run will use the same
scale as the old. If a scale parameter is supplied, then it will
override the scale parameter stored in the old structure.
A metrosamp
structure of Monte Carlo outputs (described in Details).
Store the last log-posterior value, so continuation runs don't have to recompute it.
Add code to compute MCSE.
Add code to compute Neff.
Add option to run functions on MC samples.
Allow covariance matrix for scale parameter.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.