rpg {BayesLogit}R Documentation

The Polya-Gamma Distribution


Generate a random variate from the Polya-Gamma distribution.


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

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


You may call rpg when n and z are vectors.


The number of random variates to simulate.


Degrees of freedom.


Parameter associated with tilting.


The number of elements used in sum of gammas approximation.


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

X \sim 2.0 ∑{k=1}^∞ G(n,1) / ( (k-1/2)^2 4.0 π^2 + z^2).

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

p(x|n,z) \propto \exp(-z^2/2 x) 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.


This function returns num Polya-Gamma samples.


Nicolas 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


a = c(1, 2, 3);
b = c(4, 5, 6);

## If a is only integers, use Devroye-like method.
X = rpg.devroye(100, a, b);

a = c(1.2, 2.3, 3.2);
b = c(4, 5, 6);

## If a has scalars use sum-of-gammas method.
X = rpg.gamma(100, a, b);

[Package BayesLogit version 0.1-0 Index]