The package uses a parametrization for the GIG distribution where the
density is proportional to
$$f(x) = x^{\lambda-1} e^{-\frac{1}{2}(\chi/x+\psi x)}.$$
The parameters have to satisfy the conditions
$$%
\begin{array}{l}
\lambda > 0,\, \psi > 0, \chi \geq 0, \quad\mbox{or} \\
\lambda = 0,\, \psi > 0, \chi > 0, \quad\mbox{or} \\
\lambda < 0,\, \psi \geq 0, \chi > 0.
\end{array}
$$
The generator is especially designed for the varying parameter case,
i.e., for sample size n=1
.
Note that the arguments n
, lambda
, chi
,
psi
for these two R routines are assumed to be single values.
If a vector is provided, then just the first value is used!
For the generation of large samples more efficient algorithms exist.
We recommend package Runuran.
The fast numeric inversion function pinvd.new
is usable for GIG.
It is about three times faster than rgig
for large values of n
.
However, it requires a slow set-up and is therefore not useful for the
varying parameter case.
For the usage of the Runuran functions see the last example below.
Routine rgig
applies three different algorithms depending on
the given parameters. When the density is T-concave (roughly spoken
when \(\lambda\geq 1\) or
\(\psi\,\chi\geq 1/4\)
two variants of the Ratio-of-Uniforms method due to Lehner (1989) are
used. These are quite similar to the widely used algorithm by Dapunar
but have a faster setup.
When the density is not T-concave then a new algorithm with a
uniformly rejection constant is used.
(In the latter case Dagpunar's algorithm may become extremely slow or
may sample from an invalid distribution.)