| pg.m1 | R Documentation |
Compute the first moment (mean), second moment, and variance of the Polya-Gamma distribution PG(b, z).
pg.m1(b, z)
pg.m2(b, z)
pg.var(b, z)
b |
Shape parameter. Must be positive. |
z |
Tilt parameter. May be any real number. |
For X \sim \mathrm{PG}(b, z), the moments are derived from
the moment generating function
E[e^{tX}] = \left( \frac{\cosh(z/2)}{\cosh(\sqrt{z^2/4 - t/2})} \right)^b.
The first moment is
E[X] = \frac{b \tanh(z/2)}{2z}, \quad z \neq 0,
with E[X] = b/4 when z = 0. Taylor series are used
near z = 0 for numerical stability.
pg.m2 returns E[X^2], and pg.var returns
\mathrm{Var}(X) = E[X^2] - E[X]^2.
A scalar giving the requested moment.
Nicholas G. Polson, James G. Scott, and Jesse Windle. Bayesian inference for logistic models using Polya-Gamma latent variables. https://arxiv.org/abs/1205.0310
rpg
## Mean and variance of PG(1, 0)
pg.m1(1, 0) # 0.25
pg.var(1, 0) # 1/24
## Compare sample moments to theoretical values
set.seed(1)
x <- rpg(10000, h = 2, z = 1)
mean(x)
pg.m1(2, 1)
var(x)
pg.var(2, 1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.