metrosamp: Perform Metropolis sampling with batch averaging

Description Usage Arguments Details Value To Do

View source: R/metrosamp.R

Description

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.

Usage

1
2
metrosamp(lpost, p0, nsamp, batchlen, scale = NULL, debug = FALSE,
  lp0 = NA)

Arguments

lpost

Log-posterior function

p0

Starting parameters for sampling, OR a metrosamp structure from a previous run.

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 metrosamp structure was supplied for p0; required otherwise.

debug

Flag to turn on additional debugging information.

lp0

Log-posterior for the starting parameters (p0). If not supplied it will be calculated automatically.

Details

The output metrosamp structure will be a list with the following elements:

samples

Matrix (nsamp x nparam) of parameter samples

samplp

Vector (nsamp) of log-posterior values for the samples

accept

Probability of accepting a proposal, averaged across all samples

plast

Last parameter set. Can be used to continue sampling where the last run left off.

scale

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.

proposals

The proposal parameters evaluated by the sampler.

proplp

Log-posterior for the proposals. The same notes apply as to the proposals entry.

prop_accepted

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.

Value

A metrosamp structure of Monte Carlo outputs (described in Details).

To Do


JGCRI/metrosamp documentation built on Aug. 8, 2019, 10:59 p.m.