Title: | Random Variate Generator for the GIG Distribution |
---|---|
Description: | Generator and density function for the Generalized Inverse Gaussian (GIG) distribution. |
Authors: | Josef Leydold and Wolfgang Hormann |
Maintainer: | Josef Leydold <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.8 |
Built: | 2024-12-16 06:38:53 UTC |
Source: | CRAN |
This package provides a generator and the density for the Generalized Inverse Gaussian (GIG) distribution. It uses the parametrization with density proportional to
Package: | GIGrvg |
Type: | Package |
Version: | 0.8 |
Date: | 2023-03-22 |
License: | GPL 2 or later |
Package GIGrvg provides two routines:
rgig
generates GIG distributed random variates.
It is especially designed for the varying parameter case, i.e.,
for sample size n=1
.
dgig
computes the density of the GIG distribution.
Note that the parameters of the distribution are assumed to be single values. If a vector is provided then just the first value is used!
For the very fast generation of large samples more efficient algorithms exists. We recommend package Runuran.
Josef Leydold [email protected] and Wolfgang Hörmann.
Wolfgang Hörmann and Josef Leydold (2014). Generating generalized inverse Gaussian random variates, Statistics and Computing 24, 547–557, DOI: 10.1007/s11222-013-9387-3
See also Research Report Series / Department of Statistics and Mathematics Nr. 123, Department of Statistics and Mathematics, WU Vienna University of Economics and Business, https://research.wu.ac.at/en/publications/generating-generalized-inverse-gaussian-random-variates-3.
J. S. Dagpunar (1989). An easily implemented generalised inverse Gaussian generator, Comm. Statist. B – Simulation Comput. 18, 703–710.
Karl Lehner (1989). Erzeugung von Zufallszahlen für zwei exotische stetige Verteilungen, Diploma Thesis, 107 pp., Technical University Graz, Austria (in German).
## Draw a random sample rgig(n=10, lambda=0.5, chi=0.1, psi=2) ## Evaluate the density dgig(0.3, lambda=0.5, chi=0.1, psi=2)
## Draw a random sample rgig(n=10, lambda=0.5, chi=0.1, psi=2) ## Evaluate the density dgig(0.3, lambda=0.5, chi=0.1, psi=2)
Random variate generator for the Generalized Inverse Gaussian (GIG)
distribution. The generator is especially designed for the varying
parameter case, i.e., for sample size n=1
.
rgig(n=1, lambda, chi, psi) dgig(x, lambda, chi, psi, log = FALSE)
rgig(n=1, lambda, chi, psi) dgig(x, lambda, chi, psi, log = FALSE)
n |
Number of observations |
lambda |
Shape parameter |
chi |
Shape and scale parameter. Must be nonnegative for positive lambda and positive else. |
psi |
Shape and scale parameter. Must be nonnegative for negative lambda and positive else. |
x |
Argument of pdf |
log |
If |
The package uses a parametrization for the GIG distribution where the density is proportional to
The parameters have to satisfy the conditions
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 or
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.)
rgig
creates a random sample of size n
. In case of
invalid arguments the routine simply stops execution.
dgig
evaluates the density of the GIG distribution.
Josef Leydold [email protected] and Wolfgang Hörmann.
Wolfgang Hörmann and Josef Leydold (2013). Generating generalized inverse Gaussian random variates, Statistics and Computing 24, 547–557, DOI: 10.1007/s11222-013-9387-3
J. S. Dagpunar (1989). An easily implemented generalised inverse Gaussian generator, Comm. Statist. B – Simulation Comput. 18, 703–710.
Karl Lehner (1989). Erzeugung von Zufallszahlen für zwei exotische stetige Verteilungen, Diploma Thesis, 107 pp., Technical University Graz, Austria (in German).
## Draw a random sample x <- rgig(n=10, lambda=0.5, chi=0.1, psi=2) ## Evaluate the density x <- dgig(0.3, lambda=0.5, chi=0.1, psi=2) ## Create a random sample and create a histgram y <- rgig(n=10^5,0.1,2,3) hist(y,breaks=100,freq=FALSE) xval <- seq(0,max(y),0.01) # to add plot the corresponding density lines(xval,dgig(xval,0.1,2,3)) ## Not run: ## Use a fast method from package Runuran for large samples ## (method PINV implements an approximate inversion method) library("Runuran") gen <- pinvd.new(udgig(theta=0.2, psi=0.05, chi=0.05)) x <- ur(gen, 10^6) ## End(Not run)
## Draw a random sample x <- rgig(n=10, lambda=0.5, chi=0.1, psi=2) ## Evaluate the density x <- dgig(0.3, lambda=0.5, chi=0.1, psi=2) ## Create a random sample and create a histgram y <- rgig(n=10^5,0.1,2,3) hist(y,breaks=100,freq=FALSE) xval <- seq(0,max(y),0.01) # to add plot the corresponding density lines(xval,dgig(xval,0.1,2,3)) ## Not run: ## Use a fast method from package Runuran for large samples ## (method PINV implements an approximate inversion method) library("Runuran") gen <- pinvd.new(udgig(theta=0.2, psi=0.05, chi=0.05)) x <- ur(gen, 10^6) ## End(Not run)