Sampler {Umacs}R Documentation

Generate a Markov chain sampler

Description

Generates a Markov chain sampling function given a list of parameters

Usage

Sampler(...)

Arguments

... A list of parameters including Gibbs and/or Metropolis updating routines, Raw functions and other objects

Details

Sampler generates an R function to produce simulations wrapped in an mcts object that can be coerced into random variable objects, for example.

A Sampler function call features a named argument list that represents the named parameters in a Gibbs or Metropolis sampler. The names are specified by the user (e.g. "theta", "alpha") and the values are either constants (vectors of data frames), special Umacs objects implementing a sampling scheme (Gibbs, Metropolis, etc.). Additionally, the argument list can contain assignments to special internal variables, or unnamed arguments such as raw code to be embedded in the sampling loop.

Special Umacs variables that are identified by the prepending dot (e.g. .logpost) and are not thus actual parameters in the model.

No user-defined parameter can start with a dot.

Unnamed arguments are either `raw' functions that are embedded `as is' inside the sampling loop, or special Umacs objects such as Trace objects, which provide a trace plots of a specified variable. The code that the user provides in the form of direct sampling functions (via Gibbs) or log-posterior functions (via the various Metropolis updating schemes) can have references to `global' variables that are available in the workspace, but also to `local' variables that are specified within the Sampler function call.

Ideally, the function should only have references to local variables so that the resulting sampler function is a stand-alone function that encapsulates a complete sampling environment independent of the working environment.

`Raw code' that is specified as an unnamed function in the argument list is embedded as a function, so any assignments done using the <- operator are local. To change directly the value of a parameter, use the <<- operator.

The allowed values for the parameters that (are named by the user and) can be passed as arguments are:

A constant numeric value (vector or array). The variable is made available to the functions embedded in the sampler (but not in Global Environment!), or, a SamplingScheme object that is built using one of the following possible functions: Gibbs, Metropolis, SMetropolis, PMetropolis, PSMetropolis.

These objects provide the updating and initialization functions for a Gibbs updating step, or the log-posterior function and an initialization function for a Metropolis updating step.

(Technically speaking, a `Gibbs' updating step is just a special case of a `Metropolis' updating step in the sense that all samples generated using the function of a `Gibbs' updating step are accepted unconditionally.)

The allowed values for the unnamed objects that can be passed as arguments are a Trace object, or a plain function (`raw code'). The plain function is converted internally first to a RawCode object, so giving a plain function is made possible just for convenience. See RawCode for details.

Value

An R function that can be run to produce the simulations.
See the help page for Umacs to learn about the usage of the sampling function.
The function generated by Sampler returns an mcts object that can be converted into random variable objects.

Author(s)

Jouni Kerman <jouni@kerman.com>

References

Kerman, Jouni. Umacs: A Universal Markov Chain Sampler. Technical report, Columbia University, New York.

See Also

Umacs-package for an overview of the Umacs package.

Sampler for how to create a sampler function; see the vignette for details.

Package `rv'.


[Package Umacs version 0.924 Index]