Learn R Programming

BayesLogit (version 0.3)

rpg: The Polya-Gamma Distribution

Description

Generate a random variate from the Polya-Gamma distribution.

Usage

rpg(num=1, h=1, z=0.0)

rpg.gamma(num=1, h=1, z=0.0, trunc=200)

rpg.devroye(num=1, n=1, z=0.0)

rpg.alt(num=1, h=1, z=0.0)

rpg.sp(num=1, h=1, z=0.0, track.iter=FALSE)

Arguments

num
The number of random variates to simulate.
n
Shape parameter, a positive integer
h
Shape parameter. code{h} >= 1 if not using sum of gammas method.
z
Parameter associated with tilting.
trunc
The number of elements used in sum of gammas approximation.
track.iter
The number of proposals made before accepting.

Value

  • This function returns num Polya-Gamma samples.

Details

A random variable X with distribution PG(n,z) is generated by

$$X \sim \sum_{k=1}^\infty G(n,1) / ( 2 \pi^2 (k-1/2)^2 + z^2/2).$$

The density for X may be derived from Z and PG(n,0) as

$$p(x|n,z) \propto \exp(-x z^2/2) p(x|n,0).$$

Thus PG(n,z) is an exponentially tilted PG(n,0).

Two different methods for generating this random variable are implemented. In general, you may use rpg.gamma to generate an approximation of PG(n,z) using the sum of Gammas representation above. When n is a natural number you may use rpg.devroye to sample PG(n,z). The later method is fast.

References

Nicholas G. Polson, James G. Scott, and Jesse Windle. Bayesian inference for logistic models using Polya-Gamma latent variables. http://arxiv.org/abs/1205.0310

See Also

logit.EM, logit, mlogit

Examples

Run this code
h = c(1, 2, 3);
z = c(4, 5, 6);

## Devroye-like method -- only use if h contains integers, preferably small integers.
X = rpg.devroye(100, h, z);

h = c(1.2, 2.3, 3.2);
z = c(4, 5, 6);

## Sum of gammas method -- this is slow.
X = rpg.gamma(100, h, z);

## Hybrid method -- automatically chooses best procedure.
X = rpg(100, h, z);

Run the code above in your browser using DataLab