Documentation Center

  • Trial Software
  • Product Updates

Representing Sampling Distributions Using Markov Chain Samplers

The methods in Common Generation Methods might be inadequate when sampling distributions are difficult to represent in computations. Such distributions arise, for example, in Bayesian data analysis and in the large combinatorial problems of Markov chain Monte Carlo (MCMC) simulations. An alternative is to construct a Markov chain with a stationary distribution equal to the target sampling distribution, using the states of the chain to generate random numbers after an initial burn-in period in which the state distribution converges to the target.

Using the Metropolis-Hastings Algorithm

The Metropolis-Hastings algorithm draws samples from a distribution that is only known up to a constant. Random numbers are generated from a distribution with a probability density function that is equal to or proportional to a proposal function.

To generate random numbers:

  1. Assume an initial value x(t).

  2. Draw a sample, y(t), from a proposal distribution q(y|x(t)).

  3. Accept y(t) as the next sample x(t + 1) with probability r(x(t),y(t)), and keep x(t) as the next sample x(t + 1) with probability 1 – r(x(t),y(t)), where:

  4. Increment tt+1, and repeat steps 2 and 3 until you get the desired number of samples.

Generate random numbers using the Metropolis-Hastings method with the mhsample function. To produce quality samples efficiently with the Metropolis-Hastings algorithm, it is crucial to select a good proposal distribution. If it is difficult to find an efficient proposal distribution, use the slice sampling algorithm (slicesample) without explicitly specifying a proposal distribution.

Using Slice Sampling

In instances where it is difficult to find an efficient Metropolis-Hastings proposal distribution, the slice sampling algorithm does not require an explicit specification. The slice sampling algorithm draws samples from the region under the density function using a sequence of vertical and horizontal steps. First, it selects a height at random from 0 to the density function f (x). Then, it selects a new x value at random by sampling from the horizontal "slice" of the density above the selected height. A similar slice sampling algorithm is used for a multivariate distribution.

If a function f(x) proportional to the density function is given, then do the following to generate random numbers:

  1. Assume an initial value x(t) within the domain of f(x).

  2. Draw a real value y uniformly from (0, f(x(t))), thereby defining a horizontal "slice" as S = {x: y < f(x)}.

  3. Find an interval I = (L, R) around x(t) that contains all, or much of the "slice" S.

  4. Draw the new point x(t+1) within this interval.

  5. Increment tt+1 and repeat steps 2 through 4 until you get the desired number of samples.

Slice sampling can generate random numbers from a distribution with an arbitrary form of the density function, provided that an efficient numerical procedure is available to find the interval I = (L,R), which is the "slice" of the density.

Generate random numbers using the slice sampling method with the slicesample function.

Was this topic helpful?