Login
In Cooperation with:

American Society for Quality Statistics Division

American Statistical Association

Bernoulli Society for Mathematical Statistics and Probability

Institute of Mathematical Statistics

International Biometric Society

International Chinese Statistical Association

International Society for Bayesian Analysis

International Statistical Institute

Royal Statistical Society

Statistical Society of Canada / Société statistique du Canada
- Edit Page
- |
- History
- |
- Unwatch
- |
- Suggest Correction |
- Comment |
Generating Random Variables
ref
Generating Random VariablesChristian Robert1 George Casella2 Keywords and Phrases: Random Number Generator, Probability Integral Transform, Accept Reject Algorithm, Metroplis-Hastings Algorithm, Gibbs Sampling, Markov Chains
The methods described in this article mostly rely on the possibility of producing (with a computer) a supposedly endless flow of random variables (usually iid) for well-known distributions. Such a simulation is, in turn, based on the production of uniform random variables. There are many ways in which uniform pseudorandom numbers can be generated. For example there is the Kiss algorithm of Marsaglia and Zaman (1993); details on other random number generators can be found in the books of Rubinstein (1981), Ripley (1987), Fishman (1996), and Knuth (1998).
|
![]() |
Mixture Distributions
In a mixture representation a density
has the form
(continuous) |
|||
(discrete). |
We then can simulate
- 1.
-
,
, or - 2.
-
,
Accept-Reject Methods
Another class of methods only requires the form of the density
of interest - called the target density. We simulate from a density
, called the candidate density.
Given a target density
, we need a candidate density
and a constant
such that
Accept-Reject Algorithm:
To produce a variable - 1.
- Generate
,
Uniform
; - 2.
- Accept
if
; - 3.
- Otherwise, return to 1.
Notes:
- (a).
- The densities
and
need be known only up to a multiplicative factor. - (b).
- The probability of acceptance is
, when evaluated for the normalized densities.
Envelope Accept-Reject Algorithm:
If the target densityIf there exist a density
, a function
and a constant
such that
- 1.
- Generate
,
Uniform
; - 2.
- Accept
if
; - 3.
- Otherwise, accept
if
- 4.
- Otherwise, return to 1.
Markov Chain Methods
Every simulation method discussed thus far has produced independent random variables whose distribution is exactly the target distribution. In contrast, Markov chain methods produce a sequence of dependent random variables whose distribution converges to the target. Their advantage is their applicability in complex situations.
Recall that a sequence
of random variables is a Markov chain if, for any
, the conditional distribution of
given
is the same as the distribution of
given
; that is,
Metropolis - Hastings Algorithm
The Metropolis-Hastings (M-H) algorithm (Metropolis et al. 1953, Hastings 1970) associated with the target density
and the candidate density
produces a Markov chain
through
Metropolis -Hastings
Given
,
- Generate
. - Take
where


- Then
converges in distribution to
.
Notes:
- (a).
- For
we have the independent M-H algorithm, and for
we have a symmetric M-H algorithm, where
does not depend on
. Also,
, symmetric around zero, is a random walk M-H algorithm. - (b).
- Like the Accept-Reject method, the Metropolis - Hastings algorithm only requires knowing
and
up to normalizing constants.
The Gibbs Sampler
For
, write the random variable
as
, where the
's are either uni- or multidimensional, with conditional distributions
The Gibbs sampler
Given- 1.
-
; - 2.
-
, 
- p.
-
,
Notes:
- (a).
- The densities
are called the full univariate conditionals. - (b).
- Even in a high dimensional problem, all of the simulations can be univariate.
- (c).
- The Gibbs sampler is, formally, a special case of the M-H algorithm (see Robert and Casella 2004, Section
) but with acceptance rate equal to
.
The Slice Sampler
A particular version of the Gibbs sampler, called the slice sampler (Besag and Green 1993, Damien et al. 1999), can sometimes be useful. WriteSlice sampler
Simulate- 1.
-
Uniform
; 
- k.
-
Uniform
; - k+1.
-
Uniform
, with

Application
In this section we give some guidelines for simulating different distributions. See Robert and Casella (2004, 2010) for more detailed explanations, and Devroye (1986) for more algorithms. In what follows,Arcsine
Beta
Cauchy 
If
uniform
, then
Cauchy
. Also,
Cauchy
, where
, independent.
Chi squared(
)
or Double exponential 
Exponential
Extreme Value 
. If F Distribution
, Gamma 
If
is not an integer, indirect methods can be used. For example, to generate a Gamma
use Algorithm 3.1 or 4.1 with candidate distribution Gamma
, with
and
, where
is the greatest integer less than
. For the Accept-Reject algorithm the bound on the normalized
is
. There are many other efficient algorithms.
Note:
IfLogistic 
LogisticLognormal 
,
Noncentral chi squared
,
Normal
There are many other ways to generate normal random variables.
- (a).
-
Accept Reject using Cauchy When
and
, densities of the normal and Cauchy distributions, respectively, then
. - (b).
-
Accept Reject using double exponentialWhen
and
,
. - (c).
-
Slice Sampler
yields
uniform
uniform
.
Pareto
, 
Pareto Student's 
, Uniform
Weibull 
References
- Besag, J. and Green, P.J. (1993) Spatial statistics and Bayesian computation (with discussion). J. Roy. Statist. Soc. B 55, 25-38.
- Damien, P., Wakefield, J. and Walker, S. (1999) Gibbs sampling for Bayesian non-conjugate and hierarchical models by using auxiliary variables. J. Roy. Statist. Soc. B 61(2), 331-344.
- Devroye, L. (1986) Non-Uniform Random Variate Generation. New York: Spring-Verlag.
- Fishman, G.S. (1996) Monte Carlo. New York: Springer-Verlag
- Gilks, W.R. and Wild, P. (1992) Adaptive rejection sampling for Gibbs sampling. Appl. Statist. 41, 337-348.
- Hastings, W. (1970). Monte Carlo Sampling Methods Using Markov Chains and their Application. Biometrika 57 97-109.
- Knuth, D. E. (1998). The Art of Computer Programming, Volume 2/ Seminumerical Algorithms, Third Edition. Addison Wesley, Reading.
- Marsaglia, G. (1977) The squeeze method for generating gamma variables. Computers and Mathematics with Applications, 3, 321-325.
- Marsaglia, G. and Zaman, A. (1991). A new class of random number generators. Annals Applied Probability 1, pp. 462-480.
- Metropolis, N., Rosenbluth, A.W., Rosenbluth, M.N., Teller, A.H., Teller, E. (1953) Equations of state calculations by fast computing machines. J. Chem. Phys. 21, 1087-1092.
- Ripley, B.D. (1987) Stochastic Simulation. New York: John Wiley
- Robert, C. P. and Casella, G. (2004). Monte Carlo Statistical Methods, Second Edition. New York: Spring-Verlag.
- Robert, C. P. and Casella, G. (2010). An Introduction to Monte Carlo Methods with R. New York: Spring-Verlag.
- Rubinstein, R.Y. (1981) Simulation and the Monte Carlo Method. New York: John Wiley
Footnotes
- ... Robert1
- Université Paris Dauphine, 75785 Paris cedex 16, France, and CREST, INSEE. Email: xian@ceremade.dauphine.fr
- ... Casella2
- Department of Statistics and Genetics Institute, University of Florida, Gainesville, FL 32611. Email: casella@ufl.edu




(continuous)
(discrete).