The ginormal
package provides the density function and
random variable generation from the generalized inverse normal (GIN)
distribution introduced by Robert (1991). The GIN
distribution is a way to generalize the distribution of the reciprocal
of a normal random variable. That is, the distribution generalizes the
distribution of the random variable
The GIN distribution is supported on the entire real line
This package is the first to provide an efficient sampling algorithm for drawing from the GIN distribution. We provide similar routines for the GIN distribution truncated to the positive or negative reals. Further details of the distribution, theoretical guarantees and pseudo-code for the sampling algorithms, as well as an application to Bayesian estimation of network formation models can be found in the working paper Ding, Estrada and Montoya-Blandón (2023).
To install, type from within R
:
install.packages("ginormal")
You could also install directly from the GitHub repository. To do so
from within R
, first install the devtools
package and then type:
# install.packages("devtools") # Uncomment if devtools not installed
library(devtools)
install_github(repo = "smonto2/ginormal", subdir = "R_package", ref = "main")
Examples of how to use the ginormal
package routines are
available in the GitHub
repository.
Provided with the package are four main routines:
dgin(z, alpha, mu, tau, log = TRUE, quasi = FALSE)
dtgin(z, alpha, mu, tau, sign, log = TRUE, quasi = FALSE)
rgin(size, alpha, mu, tau, algo)
rtgin(size, alpha, mu, tau, sign, algo)
The first two compute the densities and the last two are used for
random number generation. Density routines take in the quantile
z
; parameters alpha
, mu
and
tau
; and two optional logical arguments:
log
, should the logarithm of the density be returned?
Defaults to TRUE
.quasi
, should the value of the kernel (or
quasi-density) be returned? Defaults to FALSE
.Generation routines take the same parameters but require a
size
argument determining the amount of random variates to
generate. These routines only admit a parameter alpha
larger than 2. They take an additional argument algo
, which
can be either "hormann"
or "leydold"
, and
defaults to "hormann"
as our prefered method. See below for details on both points.
Those routines including “t
” in their name work for the
truncated variants. They take an additional logical argument
sign
, where sign = TRUE
implies truncation to
positive numbers sign = FALSE
to negative numbers
Let
where
Ding, Estrada and
Montoya-Blandón (2023) provide an efficient sampling algorithm for
the GIN distribution and its truncated variants for the case of
While the kernels — and therefore the sampling techniques — for the GIN and GIG distribution are similar, these two distribution share some important differences. The main is their conceptualization, as they both attempt to generalize the idea of an inverse normal distribution in different ways. The GIG distribution does so by choosing cumulants that are inverses to those of the normal distribution. The GIN distribution does so by directly using the density of the reciprocal after a change of variables. Another important difference comes from their use as conjugate priors in Bayesian analysis:
These are both mixture models with a similar structure but carry
different interpretations and thus require different posterior sampling
algorithms. This interpretation also shows why the restriction of
In R, package BAS
contains the confluent hypergeometric function. For the parabolic
cylinder function, we use a Fortran subroutine provided in the SPECFUN
library (Zhang and Jin, 1996) and our own R translation
of this function.↩︎