Density function, cumulative distribution function, quantile function
and random number generation for the generalized inverse Gaussian
distribution with parameter vector param. Utility routines are
included for the derivative of the density function and to find
suitable break points for use in determining the distribution function.
A shape parameter that by default holds a value of 1.
psi
Another shape parameter that is set to 1 by default.
lambda
Shape parameter of the GIG distribution. Common to all
forms of parameterization. By default this is set to 1.
param
Parameter vector taking the form c(chi, psi, lambda)
for rgig, or c(chi, psi) for rgig1.
method
Character. If "spline" quantiles are found from a
spline approximation to the distribution function. If
"integrate", the distribution function used is always obtained
by integration.
lower.tail
Logical. If TRUE, probabilities are
P(X<=x), otherwise as P(X>x).
KOmega
Sets the value of the Bessel function in the density or
derivative of the density. See Details.
ibfTol
Value of tolerance to be passed to
incompleteBesselK by pgig.
nmax
Value of maximum order of the approximating series to be
passed to incompleteBesselK by pgig.
nInterpol
The number of points used in qgig for cubic spline
interpolation (see splinefun) of the distribution function.
uniTol
Value of tol in
calls to uniroot. See uniroot.
...
Passes arguments to uniroot. See Details.
Details
The generalized inverse Gaussian distribution has density
for x>0, where K_lambda() is the
modified Bessel function of the third kind with order
lambda.
The generalized inverse Gaussian distribution is investigated in
detail in J<c3><b6>rgensen (1982).
Use gigChangePars to convert from the
(delta, gamma),
(alpha, beta), or
(omega, eta) parameterizations to the
(chi, psi), parameterization used above.
pgig calls the function
incompleteBesselK from the package
DistributionUtils to integrate the density function
dgig. This can be expected to be accurate to about 13 decimal
places on a 32-bit computer, often more accurate. The algorithm used
is due to Slavinsky and Safouhi (2010).
Calculation of quantiles using qgig permits the use of two
different methods. Both methods use uniroot to find the value
of x for which a given q is equal F(x) where F
denotes the cumulative distribution function. The difference is in how
the numerical approximation to F is obtained. The obvious
and more accurate method is to calculate the value of F(x)
whenever it is required using a call to pghyp. This is what
is done if the method is specified as "integrate". It is clear
that the time required for this approach is roughly linear in the
number of quantiles being calculated. A Q-Q plot of a large data set
will clearly take some time. The alternative (and default) method is
that for the major part of the distribution a spline approximation to
F(x) is calculated and quantiles found using uniroot with
this approximation. For extreme values (for which the tail probability
is less than 10^(-7)), the integration method is still
used even when the method specifed is "spline".
If accurate probabilities or quantiles are required, tolerances
(intTol and uniTol) should be set to small values, say
10^(-10) or 10^(-12) with method
= "integrate". Generally then accuracy might be expected to be at
least 10^(-9). If the default values of the functions
are used, accuracy can only be expected to be around
10^(-4). Note that on 32-bit systems
.Machine$double.eps^0.25 = 0.0001220703 is a typical value.
Generalized inverse Gaussian observations are obtained via the
algorithm of Dagpunar (1989).
Value
dgig gives the density, pgig gives the distribution
function, qgig gives the quantile function, and rgig
generates random variates. rgig1 generates random variates in
the special case where lambda = 1.
J<c3><b6>rgensen, B. (1982). Statistical Properties of
the Generalized Inverse Gaussian Distribution. Lecture Notes in
Statistics, Vol. 9, Springer-Verlag, New York.
Slevinsky, Richard M., and Safouhi, Hassan (2010) A recursive
algorithm for the G transformation and accurate computation of
incomplete Bessel functions. Appl. Numer. Math., In press.
See Also
safeIntegrate,
integrate for its shortfalls, splinefun,
uniroot and gigChangePars for changing
parameters to the (chi,psi) parameterization,
dghyp for the generalized hyperbolic distribution.
Examples
param <- c(2, 3, 1)
gigRange <- gigCalcRange(param = param, tol = 10^(-3))
par(mfrow = c(1, 2))
curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Density of the\n Generalized Inverse Gaussian")
curve(pgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Distribution Function of the\n Generalized Inverse Gaussian")
dataVector <- rgig(500, param = param)
curve(dgig(x, param = param), range(dataVector)[1], range(dataVector)[2],
n = 500)
hist(dataVector, freq = FALSE, add = TRUE)
title("Density and Histogram\n of the Generalized Inverse Gaussian")
logHist(dataVector, main =
"Log-Density and Log-Histogram\n of the Generalized Inverse Gaussian")
curve(log(dgig(x, param = param)), add = TRUE,
range(dataVector)[1], range(dataVector)[2], n = 500)
par(mfrow = c(2, 1))
curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Density of the\n Generalized Inverse Gaussian")
curve(ddgig(x, param = param), from = gigRange[1], to = gigRange[2],
n = 1000)
title("Derivative of the Density\n of the Generalized Inverse Gaussian")
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(GeneralizedHyperbolic)
Loading required package: DistributionUtils
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/GeneralizedHyperbolic/dgig.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Generalized Inverse Gaussian
> ### Title: Generalized Inverse Gaussian Distribution
> ### Aliases: dgig pgig qgig rgig rgig1 ddgig
> ### Keywords: distribution
>
> ### ** Examples
>
> param <- c(2, 3, 1)
> gigRange <- gigCalcRange(param = param, tol = 10^(-3))
> par(mfrow = c(1, 2))
> curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
+ n = 1000)
> title("Density of the\n Generalized Inverse Gaussian")
> curve(pgig(x, param = param), from = gigRange[1], to = gigRange[2],
+ n = 1000)
> title("Distribution Function of the\n Generalized Inverse Gaussian")
> dataVector <- rgig(500, param = param)
> curve(dgig(x, param = param), range(dataVector)[1], range(dataVector)[2],
+ n = 500)
> hist(dataVector, freq = FALSE, add = TRUE)
> title("Density and Histogram\n of the Generalized Inverse Gaussian")
> logHist(dataVector, main =
+ "Log-Density and Log-Histogram\n of the Generalized Inverse Gaussian")
> curve(log(dgig(x, param = param)), add = TRUE,
+ range(dataVector)[1], range(dataVector)[2], n = 500)
> par(mfrow = c(2, 1))
> curve(dgig(x, param = param), from = gigRange[1], to = gigRange[2],
+ n = 1000)
> title("Density of the\n Generalized Inverse Gaussian")
> curve(ddgig(x, param = param), from = gigRange[1], to = gigRange[2],
+ n = 1000)
> title("Derivative of the Density\n of the Generalized Inverse Gaussian")
>
>
>
>
>
> dev.off()
null device
1
>