Description Usage Arguments sampler_base binary sampler RW sampler RW_block sampler RW_llFunction sampler slice sampler ess sampler AF_slice sampler crossLevel sampler RW_llFunction_block sampler RW_PF sampler RW_PF_block sampler RW_multinomial sampler RW_dirichlet sampler CAR_normal sampler posterior_predictive sampler Author(s) References See Also Examples
Details of the MCMC sampling algorithms provided with the NIMBLE MCMC engine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  sampler_BASE()
sampler_posterior_predictive(model, mvSaved, target, control)
sampler_binary(model, mvSaved, target, control)
sampler_categorical(model, mvSaved, target, control)
sampler_RW(model, mvSaved, target, control)
sampler_RW_block(model, mvSaved, target, control)
sampler_RW_llFunction(model, mvSaved, target, control)
sampler_slice(model, mvSaved, target, control)
sampler_ess(model, mvSaved, target, control)
sampler_AF_slice(model, mvSaved, target, control)
sampler_crossLevel(model, mvSaved, target, control)
sampler_RW_llFunction_block(model, mvSaved, target, control)
sampler_RW_PF(model, mvSaved, target, control)
sampler_RW_PF_block(model, mvSaved, target, control)
sampler_RW_multinomial(model, mvSaved, target, control)
sampler_RW_dirichlet(model, mvSaved, target, control)
sampler_CAR_normal(model, mvSaved, target, control)

model 
(uncompiled) model on which the MCMC is to be run 
mvSaved 

target 
node(s) on which the sampler will be used 
control 
named list that controls the precise behavior of the sampler, with elements specific to 
sampler_base
base class for new samplers
When you write a new sampler for use in a NIMBLE MCMC (see User Manual), you must include contains = sampler_BASE
.
The binary sampler performs Gibbs sampling for binaryvalued (discrete 0/1) nodes. This can only be used for nodes following either a dbern(p)
or dbinom(p, size=1)
distribution.
The binary sampler accepts no control list arguments.
The RW sampler executes adaptive MetropolisHastings sampling with a normal proposal distribution (Metropolis, 1953), implementing the adaptation routine given in Shaby and Wells, 2011. This sampler can be applied to any scalar continuousvalued stochastic node, and can optionally sample on a log scale.
The RW sampler accepts the following control list elements:
log. A logical argument, specifying whether the sampler should operate on the log scale. (default = FALSE)
reflective. A logical argument, specifying whether the normal proposal distribution should reflect to stay within the range of the target distribution. (default = FALSE)
adaptive. A logical argument, specifying whether the sampler should adapt the scale (proposal standard deviation) throughout the course of MCMC execution to achieve a theoretically desirable acceptance rate. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. Every adaptInterval MCMC iterations (prior to thinning), the RW sampler will perform its adaptation procedure. This updates the scale variable, based upon the sampler's achieved acceptance rate over the past adaptInterval iterations. (default = 200)
scale. The initial value of the normal proposal standard deviation. If adaptive = FALSE, scale will never change. (default = 1)
The RW sampler cannot be used with options log=TRUE and reflective=TRUE, i.e. it cannot do reflective sampling on a log scale.
The RW_block sampler performs a simultaneous update of one or more model nodes, using an adaptive MetropolisHastings algorithm with a multivariate normal proposal distribution (Roberts and Sahu, 1997), implementing the adaptation routine given in Shaby and Wells, 2011. This sampler may be applied to any set of continuousvalued model nodes, to any single continuousvalued multivariate model node, or to any combination thereof.
The RW_block sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the scale (a coefficient for the entire proposal covariance matrix) and propCov (the multivariate normal proposal covariance matrix) throughout the course of MCMC execution. If only the scale should undergo adaptation, this argument should be specified as TRUE. (default = TRUE)
adaptScaleOnly. A logical argument, specifying whether adaption should be done only for scale (TRUE) or also for provCov (FALSE). This argument is only relevant when adaptive = TRUE. When adaptScaleOnly = FALSE, both scale and propCov undergo adaptation; the sampler tunes the scaling to achieve a theoretically good acceptance rate, and the proposal covariance to mimic that of the empirical samples. When adaptScaleOnly = TRUE, only the proposal scale is adapted. (default = FALSE)
adaptInterval. The interval on which to perform adaptation. Every adaptInterval MCMC iterations (prior to thinning), the RW_block sampler will perform its adaptation procedure, based on the past adaptInterval iterations. (default = 200)
scale. The initial value of the scalar multiplier for propCov. If adaptive = FALSE, scale will never change. (default = 1)
propCov. The initial covariance matrix for the multivariate normal proposal distribution. This element may be equal to the character string 'identity', in which case the identity matrix of the appropriate dimension will be used for the initial proposal covariance matrix. (default = 'identity')
Sometimes it is useful to control the log likelihood calculations used for an MCMC updater instead of simply using the model. For example, one could use a sampler with a log likelihood that analytically (or numerically) integrates over latent model nodes. Or one could use a sampler with a log likelihood that comes from a stochastic approximation such as a particle filter, allowing composition of a particle MCMC (PMCMC) algorithm (Andrieu et al., 2010). The RW_llFunction sampler handles this by using a MetropolisHastings algorithm with a normal proposal distribution and a userprovided loglikelihood function. To allow compiled execution, the loglikelihood function must be provided as a specialized instance of a nimbleFunction. The loglikelihood function may use the same model as the MCMC as a setup argument, but if so the state of the model should be unchanged during execution of the function (or you must understand the implications otherwise).
The RW_llFunction sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the scale (proposal standard deviation) throughout the course of MCMC execution. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. (default = 200)
scale. The initial value of the normal proposal standard deviation. (default = 1)
llFunction. A specialized nimbleFunction that accepts no arguments and returns a scalar double number. The return value must be the total loglikelihood of all stochastic dependents of the target nodes – and, if includesTarget = TRUE, of the target node(s) themselves – or whatever surrogate is being used for the total loglikelihood. This is a required element with no default.
includesTarget. Logical variable indicating whether the return value of llFunction includes the loglikelihood associated with target. This is a required element with no default.
The slice sampler performs slice sampling of the scalar node to which it is applied (Neal, 2003). This sampler can operate on either continuousvalued or discretevalued scalar nodes. The slice sampler performs a 'stepping out' procedure, in which the slice is iteratively expanded to the left or right by an amount sliceWidth. This sampler is optionally adaptive, governed by a control list element, whereby the value of sliceWidth is adapted towards the observed absolute difference between successive samples.
The slice sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler will adapt the value of sliceWidth throughout the course of MCMC execution. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. (default = 200)
sliceWidth. The initial value of the width of each slice, and also the width of the expansion during the iterative 'stepping out' procedure. (default = 1)
sliceMaxSteps. The maximum number of expansions which may occur during the 'stepping out' procedure. (default = 100)
The ess sampler performs elliptical slice sampling of a single node, which must follow a multivariate normal distribution (Murray, 2010). The algorithm is an extension of slice sampling (Neal, 2003), generalized to the multivariate normal context. An auxilliary variable is used to identify points on an ellipse (which passes through the current node value) as candidate samples, which are accepted contingent upon a likelihood evaluation at that point. This algorithm requires no tuning parameters and therefore no period of adaptation, and may result in very efficient sampling from multivariate Gaussian distributions.
The ess sampler accepts no control list arguments.
The automated factor slice sampler conducts a slice sampling algorithm on one or more model nodes. The sampler uses the eigenvectors of the posterior covariance between these nodes as an orthogonal basis on which to perform its 'stepping Out' procedure. The sampler is adaptive in updating both the width of the slices and the values of the eigenvectors. The sampler can be applied to ay be applied to any set of continuous or discretevalued model nodes, to any single continuous or discretevalued multivariate model node, or to any combination thereof. The automated factor slice sampler accepts the following control list elements:
sliceWidths. A numeric vector of initial slice widths. The length of the vector must be equal to the sum of the lengths of all nodes being used by the automated factor slice sampler. Defaults to a vector of 1's.
sliceAdaptFactorMaxIter. The number of iterations for which the factors (eigenvectors) will continue to adapt to the posterior correlation. (default = 15000)
sliceAdaptFactorInterval. The interval on which to perform factor adaptation. (default = 1000)
sliceAdaptWidthMaxIter. The maximum number of iterations for which to adapt the widths for a given set of factors. (default = 512)
sliceAdaptWidthTolerance. The tolerance for when widths no longer need to adapt, between 0 and 0.5. (default = 0.1)
sliceMaxSteps. The maximum number of expansions which may occur during the 'stepping out' procedure. (default = 100)
This sampler is constructed to perform simultaneous updates across two levels of stochastic dependence in the model structure. This is possible when all stochastic descendents of node(s) at one level have conjugate relationships with their own stochastic descendents. In this situation, a MetropolisHastings algorithm may be used, in which a multivariate normal proposal distribution is used for the higherlevel nodes, and the corresponding proposals for the lowerlevel nodes undergo Gibbs (conjugate) sampling. The joint proposal is either accepted or rejected for all nodes involved based upon the MetropolisHastings ratio.
The requirement that all stochastic descendents of the target nodes must themselves have only conjugate descendents will be checked when the MCMC algorithm is built. This sampler is useful when there is strong dependence across the levels of a model that causes problems with convergence or mixing.
The crossLevel sampler accepts the following control list elements:
adaptive. Logical argument, specifying whether the multivariate normal proposal distribution for the target nodes should be adaptived. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. (default = 200)
scale. The initial value of the scalar multiplier for propCov. (default = 1)
propCov. The initial covariance matrix for the multivariate normal proposal distribution. This element may be equal to the character string 'identity' or any positive definite matrix of the appropriate dimensions. (default = 'identity')
Sometimes it is useful to control the log likelihood calculations used for an MCMC updater instead of simply using the model. For example, one could use a sampler with a log likelihood that analytically (or numerically) integrates over latent model nodes. Or one could use a sampler with a log likelihood that comes from a stochastic approximation such as a particle filter, allowing composition of a particle MCMC (PMCMC) algorithm (Andrieu et al., 2010) (but see samplers listed below for NIMBLE's direct implementation of PMCMC). The RW_llFunctionBlock
sampler handles this by using a MetropolisHastings algorithm with a multivariate normal proposal distribution and a userprovided loglikelihood function. To allow compiled execution, the loglikelihood function must be provided as a specialized instance of a nimbleFunction. The loglikelihood function may use the same model as the MCMC as a setup argument, but if so the state of the model should be unchanged during execution of the function (or you must understand the implications otherwise).
The RW_llFunctionBlock sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the proposal covariance throughout the course of MCMC execution. (default is TRUE)
adaptScaleOnly. A logical argument, specifying whether adaption should be done only for scale (TRUE) or also for provCov (FALSE). This argument is only relevant when adaptive = TRUE. When adaptScaleOnly = FALSE, both scale and propCov undergo adaptation; the sampler tunes the scaling to achieve a theoretically good acceptance rate, and the proposal covariance to mimic that of the empirical samples. When adaptScaleOnly = TRUE, only the proposal scale is adapted. (default = FALSE)
adaptInterval. The interval on which to perform adaptation. (default = 200)
scale. The initial value of the scalar multiplier for propCov. If adaptive = FALSE, scale will never change. (default = 1)
propCov. The initial covariance matrix for the multivariate normal proposal distribution. This element may be equal to the character string 'identity', in which case the identity matrix of the appropriate dimension will be used for the initial proposal covariance matrix. (default = 'identity')
llFunction. A specialized nimbleFunction that accepts no arguments and returns a scalar double number. The return value must be the total loglikelihood of all stochastic dependents of the target nodes – and, if includesTarget = TRUE, of the target node(s) themselves – or whatever surrogate is being used for the total loglikelihood. This is a required element with no default.
includesTarget. Logical variable indicating whether the return value of llFunction includes the loglikelihood associated with target. This is a required element with no default.
The particle filter sampler allows the user to perform PMCMC (Andrieu et al., 2010), integrating over latent nodes in the model to sample toplevel parameters. The RW_PF
sampler uses a MetropolisHastings algorithm with a univariate normal proposal distribution for a scalar parameter. Note that latent states can be sampled as well, but the toplevel parameter being sampled must be a scalar. A bootstrap or auxiliary particle filter can be used to integrate over latent states.
The RW_PF
sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the scale (proposal standard deviation) throughout the course of MCMC execution to achieve a theoretically desirable acceptance rate. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. Every adaptInterval MCMC iterations (prior to thinning), the RW sampler will perform its adaptation procedure. This updates the scale variable, based upon the sampler's achieved acceptance rate over the past adaptInterval iterations. (default = 200)
scale. The initial value of the normal proposal standard deviation. If adaptive = FALSE
, scale will never change. (default = 1)
pfNparticles. The number of particles to use in the approximation to the log likelihood of the data (default = 1000).
latents. Character vector specifying the latent model nodes over which the particle filter will stochastically integrate over to estimate the loglikelihood function.
pfType. Character argument specifying the type of particle filter that should be used for likelihood approximation. Choose from "bootstrap"
and "auxiliary"
. Defaults to "bootstrap"
.
pfLookahead. Optional character argument specifying the lookahead function for the auxiliary particle filter. Choose from "simulate"
and "mean"
. Only applicable if pfType
is set to "auxiliary"
.
pfResample. A logical argument, specifying whether to resample log likelihood given current parameters at beginning of each MCMC step, or whether to use log likelihood from previous step.
pfOptimizeNparticles. A logical argument, specifying whether to automatically determine the optimal number of particles to use, based on Pitt and Shephard (2011). This will override any value of pfNparticles
specified above.
The particle filter sampler allows the user to perform PMCMC (Andrieu et al., 2010), integrating over latent nodes in the model to sample toplevel parameters. The RW_PF_block
sampler uses a MetropolisHastings algorithm with a multivariate normal proposal distribution. A bootstrap or auxiliary particle filter can be used to integrate over latent states.
The RW_PF_block
sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the proposal covariance throughout the course of MCMC execution. (default = TRUE)
adaptScaleOnly. A logical argument, specifying whether adaption should be done only for scale
(TRUE) or also for provCov
(FALSE). This argument is only relevant when adaptive = TRUE
. When adaptScaleOnly = FALSE
, both scale
and propCov
undergo adaptation; the sampler tunes the scaling to achieve a theoretically good acceptance rate, and the proposal covariance to mimic that of the empirical samples. When adaptScaleOnly = TRUE
, only the proposal scale is adapted. (default = FALSE)
adaptInterval. The interval on which to perform adaptation. (default = 200)
scale. The initial value of the scalar multiplier for propCov
. If adaptive = FALSE
, scale
will never change. (default = 1)
propCov. The initial covariance matrix for the multivariate normal proposal distribution. This element may be equal to the 'identity'
, in which case the identity matrix of the appropriate dimension will be used for the initial proposal covariance matrix. (default is 'identity'
)
pfNparticles. The number of particles to use in the approximation to the log likelihood of the data (default = 1000).
latents. Character vector specifying the latent model nodes over which the particle filter will stochastically integrate to estimate the loglikelihood function.
pfResample. A logical argument, specifying whether to resample log likelihood given current parameters at beginning of each mcmc step, or whether to use log likelihood from previous step.
pfType. Character argument specifying the type of particle filter that should be used for likelihood approximation. Choose from "bootstrap"
and "auxiliary"
. Defaults to "bootstrap"
.
pfLookahead. Optional character argument specifying the lookahead function for the auxiliary particle filter. Choose from "simulate"
and "mean"
. Only applicable if pfType = "auxiliary"
.
pfOptimizeNparticles. A logical argument, specifying whether to automatically determine the optimal number of particles to use, based on Pitt and Shephard (2011). This will override any value of pfNparticles
specified above.
This sampler is designed for sampling multinomial target distributions. The sampler performs a series of MetropolisHastings steps between pairs of groups. Proposals are generated via a draw from a binomial distribution, whereafter the proposed number density is moved from one group to another group. The acceptance or rejection of these proposals follows a standard MetropolisHastings procedure. Probabilities for the random binomial proposals are adapted to a target acceptance rate of 0.5.
The RW_multinomial
sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should adapt the binomial proposal probabilities throughout the course of MCMC execution. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. A minimum value of 100 is required. (default = 200)
This sampler is designed for sampling nonconjugate Dirichlet distributions. The sampler performs a series of MetropolisHastings updates (on the log scale) to each component of a gammareparameterization of the target Dirichlet distribution. The acceptance or rejection of these proposals follows a standard MetropolisHastings procedure.
The RW_dirichlet
sampler accepts the following control list elements:
adaptive. A logical argument, specifying whether the sampler should independently adapt the scale (proposal standard deviation, on the log scale) for each componentwise MetropolisHasting update, to achieve a theoretically desirable acceptance rate for each. (default = TRUE)
adaptInterval. The interval on which to perform adaptation. Every adaptInterval MCMC iterations (prior to thinning), the sampler will perform its adaptation procedure. (default = 200)
scale. The initial value of the proposal standard deviation (on the log scale) for each component of the reparameterized Dirichlet distribution. If adaptive = FALSE, the proposal standard deviations will never change. (default = 1)
The CAR_normal sampler operates uniquely on improper (intrinsic) Gaussian conditional autoregressive (CAR) nodes, those with a dcar_normal
prior distribution. It internally assigns one of three univariate samplers to each dimension of the target node: a posterior predictive, conjugate, or RW sampler; however these component samplers are specialized to operate on dimensions of a dcar_normal
distribution.
The CAR_normal sampler accepts the following control list elements:
adaptive
. A logical argument, specifying whether any component RW samplers should adapt the scale (proposal standard deviation), to achieve a theoretically desirable acceptance rate. (default = TRUE
)
adaptInterval
. The interval on which to perform adaptation for any component RW samplers. Every adaptInterval
MCMC iterations (prior to thinning), component RW samplers will perform an adaptation procedure. This updates the scale
variable, based upon the sampler's achieved acceptance rate over the past adaptInterval
iterations. (default = 200)
scale
. The initial value of the normal proposal standard deviation for any component RW samplers. If adaptive = FALSE
, scale
will never change. (default = 1)
The posterior_predictive sampler is only appropriate for use on terminal stochastic nodes. Note that such nodes play no role in inference but have often been included in BUGS models to accomplish posterior predictive checks. NIMBLE allows posterior predictive values to be simulated independently of running MCMC, for example by writing a nimbleFunction to do so. This means that in many cases where terminal stochastic nodes have been included in BUGS models, they are not needed when using NIMBLE.
The posterior_predictive sampler functions by calling the simulate() method of relevant node, then updating model probabilities and deterministic dependent nodes. The application of a posterior_predictive sampler to any nonterminal node will result in invalid posterior inferences. The posterior_predictive sampler will automatically be assigned to all terminal, nondata stochastic nodes in a model by the default MCMC configuration, so it is uncommon to manually assign this sampler.
The posterior_predictive sampler accepts no control list arguments.
Daniel Turek
Andrieu, C., Doucet, A., and Holenstein, R. (2010). Particle Markov Chain Monte Carlo Methods. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 72(3), 269342.
Metropolis, N., Rosenbluth, A. W., Rosenbluth, M. N., Teller, A. H., and Teller, E. (1953). Equation of State Calculations by Fast Computing Machines. The Journal of Chemical Physics, 21(6), 10871092.
Neal, Radford M. (2003). Slice Sampling. The Annals of Statistics, 31(3), 705741.
Murray, I., Prescott Adams, R., and MacKay, D. J. C. (2010). Elliptical Slice Sampling. arXiv eprints, arXiv:1001.0175.
Pitt, M.K. and Shephard, N. (1999). Filtering via simulation: Auxiliary particle filters. Journal of the American Statistical Association 94(446), 590599.
Roberts, G. O. and S. K. Sahu (1997). Updating Schemes, Correlation Structure, Blocking and Parameterization for the Gibbs Sampler. Journal of the Royal Statistical Society: Series B (Statistical Methodology), 59(2), 291317.
Shaby, B. and M. Wells (2011). Exploring an Adaptive Metropolis Algorithm. 201114. Department of Statistics, Duke University.
Tibbits, M. M., Groendyke, C., Haran, M., and Liechty, J. C. (2014). Automated Factor Slice Sampling. Journal of Computational and Graphical Statistics, 23(2), 543563.
configureMCMC
addSampler
buildMCMC
runMCMC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29  ## y[1] ~ dbern() or dbinom():
# mcmcConf$addSampler(target = 'y[1]', type = 'binary')
# mcmcConf$addSampler(target = 'a', type = 'RW',
# control = list(log = TRUE, adaptive = FALSE, scale = 3))
# mcmcConf$addSampler(target = 'b', type = 'RW',
# control = list(adaptive = TRUE, adaptInterval = 200))
# mcmcConf$addSampler(target = 'p', type = 'RW',
# control = list(reflective = TRUE))
## a, b, and c all continuousvalued:
# mcmcConf$addSampler(target = c('a', 'b', 'c'), type = 'RW_block')
# mcmcConf$addSampler(target = 'p', type = 'RW_llFunction',
# control = list(llFunction = RllFun, includesTarget = FALSE))
# mcmcConf$addSampler(target = 'y[1]', type = 'slice',
# control = list(adaptive = FALSE, sliceWidth = 3))
# mcmcConf$addSampler(target = 'y[2]', type = 'slice',
# control = list(adaptive = TRUE, sliceMaxSteps = 1))
# mcmcConf$addSampler(target = 'x[1:10]', type = 'ess') ## x[1:10] ~ dmnorm()
# mcmcConf$addSampler(target = 'x[1:5]', type = 'RW_multinomial') ## x[1:5] ~ dmulti()
# mcmcConf$addSampler(target = 'p[1:5]', type = 'RW_dirichlet') ## p[1:5] ~ ddirch()
## y[1] is a posterior predictive node:
# mcmcConf$addSampler(target = 'y[1]', type = 'posterior_predictive')

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.