Rev Language Reference


mcmc - MCMC analysis object

The MCMC analysis object keeps a model and the associated moves and monitors. The object is used to run Markov chain Monte Carlo (MCMC) simulation on the model, using the provided moves, to obtain a sample of the posterior probability distribution. During the analysis, the monitors are responsible for sampling model parameters of interest.

Usage

mcmc(Model model, Monitor[] monitors, Move[] moves, String moveschedule, Natural nruns, String combine, Natural ntries, RealPos priorHeat, RealPos likelihoodHeat, RealPos posteriorHeat)

Arguments

model : Model (pass by value)
The model graph.
monitors : Monitor[] (pass by value)
The monitors used for this analysis.
moves : Move[] (pass by value)
The moves used for this analysis.
moveschedule : String (pass by value)
The strategy how the moves are used.
Default : random
Options : sequential|random|single
nruns : Natural (pass by value)
The number of replicate analyses.
Default : 1
combine : String (pass by value)
How should we combine the traces once the simulation is finished.
Default : none
Options : sequential|mixed|none
ntries : Natural (pass by value)
The number of initialization attempts.
Default : 1000
priorHeat : RealPos (pass by value)
The power that the prior will be raised to.
Default : 1
likelihoodHeat : RealPos (pass by value)
The power that the likelihood will be raised to.
Default : 1
posteriorHeat : RealPos (pass by value)
The power that the posterior will be raised to.
Default : 1

Details

The MCMC analysis object produced by a call to this function keeps copies of the model and the associated moves and monitors. The MCMC analysis object is used to run Markov chain Monte Carlo (MCMC) simulation on the model, using the provided moves, to obtain a sample of the posterior probability distribution. During the analysis, the monitors are responsible for sampling model parameters of interest. The `mcmc.run()` method begins or continues an MCMC analysis. During each iteration of an analysis, moves are selected from those listed in the `moves` parameter. With the default `moveschedule = "random"`, or `moveschedule = "sequential"`, moves will be attempted, on average, `weight` times per iteration. If `moveschedule = "single"`, RevBayes will attempt exactly one move per iteration, corresponding to the behavior of software like BEAST or MrBayes. See Höhna et al. (2017) for details. The run will continue for `generations` iterations, or until a stopping rule is triggered: perhaps once the run has attained convergence, or after a certain amount of time has passed. The run will be terminated once *all* convergence rules ([`srGelmanRubin()`], [`srGeweke()`], [`srMinESS()`], [`srStationarity()`]) in its `StoppingRule[]` argument have been fulfilled; or once *any* threshold rules ([`srMaxTime()`], [`srMaxIteration()`]) are met. The parameters `checkpointFile` and `checkpointInterval` generate snapshots of the current state of the MCMC run from which the run can be continued if interrupted using the `mcmc.initializeFromCheckpoint()` method. The `mcmc.initializeFromCheckpoint()` method allows an analysis to be continued from a checkpoint file. New generations will be appended to existing monitor files.

Example

# Create a simple model (unclamped)
a ~ dnExponential(1)
mymodel = model(a)

# Create a move vector and a monitor vector
moves[1] = mvScale( a, lambda = 1.0, weight = 1.0 )
monitors[1] = mnFile( a, filename = "output/out.log" )

# Create an mcmc object
mymcmcObject = mcmc( mymodel, monitors, moves )

# Run a short analysis
mymcmcObject.burnin( generations = 400, tuningInterval = 100 )
mymcmcObject.run( generations = 400, checkpointFile = "output/out.ckp", checkpointInterval = 100 )

# print the summary of the operators (now tuned)
mymcmcObject.operatorSummary()

# Resume analysis from the checkpoint file
mymcmcObject.initializeFromCheckpoint( "output/out.ckp" )

# Conduct an additional 400 generations
mymcmcObject.run( generations = 400 )

# Stopping rules are defined on the total number of generations
# This command will have no effect, as 400 generations have already been performed.
mymcmcObject.run( rules = [ srMaxIteration(400) ] )

Methods

See Also