Rev Language Reference


mnModel - Monitor of Numeric Parameters

Saves the values of numeric parameters sampled by an MCMC analysis to a file.

Usage

mnModel(Bool posterior, Bool likelihood, Bool prior, Bool stochasticOnly, String[] exclude, String format, Bool append, String filename, IntegerPos printgen, String separator, Bool version)

Arguments

posterior : Bool (pass by value)
Should we print the joint posterior probability?
Default : TRUE
likelihood : Bool (pass by value)
Should we print the likelihood?
Default : TRUE
prior : Bool (pass by value)
Should we print the joint prior probability?
Default : TRUE
stochasticOnly : Bool (pass by value)
Should we monitor stochastic variables only?
Default : FALSE
exclude : String[] (pass by value)
Variables to exclude from the monitor
Default : [ ]
format : String (pass by value)
Output format
Default : separator
append : Bool (pass by value)
Should we append or overwrite if the file exists?
Default : FALSE
filename : String (pass by value)
The name of the file for storing the samples.
printgen : IntegerPos (pass by value)
The number of generations between stored samples.
Default : 1
separator : String (pass by value)
The separator/delimiter between columns in the file.
Default :
version : Bool (pass by value)
Should we record the software version?
Default : FALSE

Details

Every `printgen` iterations, the `mnModel` monitor saves the values of numeric parameters or vectors thereof (including nested vectors) to a file known as a trace file, created at the path specified by the `filename` argument. Each row of a trace file corresponds to one recorded iteration of an MCMC simulation (or of an alternative sampler such as MCMCMC). The first column of a trace file records the "Iteration" at which the samples were taken. By default, the next three columns record the "Posterior", "Likelihood", and "Prior" of the corresponding state of the simulation. Each of these can be suppressed by setting the corresponding argument (`posterior`, `likelihood`, `prior`) to `FALSE`. The subsequent columns represent individual variables. By default, `mnModel` automatically monitors all non-constant (i.e., both stochastic and deterministic) numeric variables in the graphical model. This behavior can be suppressed by setting `stochasticOnly=TRUE`, and individual variables can be omitted from the trace file using the `exclude` argument. By default, `mnModel` prints tab-separated files, but it can also output JSON files (by setting `format="json"`) or employ a different column separator (specified using the `separator` argument) to produce tabular files in alternative formats such as CSV. Tabular trace files produced by `mnModel` can be read back into RevBayes using the `readTrace` function. The tab-separated trace files produced under default settings can also be parsed by a number of third-party tools such as Tracer (Rambaut et al. 2018) or RWTY (Warren et al. 2017). The `mnModel` can only save the values of simple, numeric parameters. More complex parameters such as trees or rate matrices can instead be recorded using the `mnFile` monitor.

Example

# Binomial example: estimate success probability given 7 successes out of 20 trials
r ~ dnExp(10)
p := Probability(ifelse(r < 1, r, 1))
n <- 20
k ~ dnBinomial(n, p)
k.clamp(7)
mymodel = model(k)

moves = VectorMoves()
moves.append( mvScale(r, weight=1) )

# Set up a monitor for both r and p
all_params = mnModel(filename="all_params.log", printgen=10)
# Set up a monitor for r only
stoch_only = mnModel(filename="stoch_only.log", stochasticOnly=TRUE, printgen=10)
# Set up a monitor for p only
p_only = mnModel(filename="p_only.log", exclude=["r"], printgen=10)

# Apply the monitors and run a short simulation
mymcmc = mcmc(model=mymodel, moves=moves, monitors=[all_params, stoch_only, p_only])
mymcmc.run(generations=1000)

Methods

See Also