sampler_categorical_general {nimbleSCR} | R Documentation |
nimble
MCMC sampler function for general categorial distributions
Description
The categorical_general
sampler operates within nimble
's MCMC engine to perform Gibbs sampling for a single node, which must in essence follow a categorical distribution. However, the prior distribution need not be nimble
's dcat
distribution, but rather can be any (potentially user-defined) distribution which has the same support as a standard categorical (dcat
) distribution. Specifically: the distribution must define a discrete random variable, which can only attain values from the set 1, 2, 3, ..., numCategories
.
The categorical_general
sampler requires one control list argument, named numCategories
, which specifies the fixed upper-bound for the range of the random variable.
The categorical_general
sampler is designed to be used in nimble
's MCMC engine, and can be added to an MCMC configuration object using the addSampler
method. See help(configureMCMC)
for more information about MCMC configuration objects and adding custom samplers.
Usage
sampler_categorical_general(model, mvSaved, target, control)
Arguments
model |
(uncompiled) model on which the MCMC is to be run. |
mvSaved |
|
target |
node on which the sampler will operate. |
control |
named list containing an elemente named |
Author(s)
Daniel Turek
Examples
## Not run:
## define custom dmy_categorical distribution as a nimbleFunction
dmy_categorical <- nimbleFunction(...)
## nimble model code, using custom-written dmy_categorical distribution
code <- nimbleCode({
x ~ dmy_categorical(...)
})
## create NIMBLE model object
Rmodel <- nimbleModel(code)
## create MCMC configuration object with no samplers
conf <- configureMCMC(Rmodel, nodes = NULL)
## add categorical_general sampler to MCMC configuration
conf$addSampler(target = 'x', type = 'categorical_general', control = list(numCategories = 10))
## build MCMC algorithm
Rmcmc <- buildMCMC(conf)
## compile model and MCMC, run MCMC algorithm
## End(Not run)