gig-distribution: The Generalized Inverse Gaussian Distribution

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Density, distribution function, quantile function, random generation, expected shortfall and expected value and variance for the generalized inverse gaussian distribution.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
dgig(x, lambda = 1, chi = 1, psi = 1, logvalue = FALSE)

pgig(q, lambda = 1, chi = 1, psi = 1, ...)

qgig(p, lambda = 1, chi = 1, psi = 1, method = c("integration", "splines"),
     spline.points = 200, subdivisions = 200,
     root.tol = .Machine$double.eps^0.5,
     rel.tol = root.tol^1.5, abs.tol = rel.tol, ...)

rgig(n = 10, lambda = 1, chi = 1, psi = 1)

ESgig(alpha, lambda = 1, chi = 1, psi = 1, distr = c("return", "loss"), ...)

Egig(lambda, chi, psi, func = c("x", "logx", "1/x", "var"), check.pars = TRUE)

Arguments

x

A vector of quantiles.

q

A vector of quantiles.

p

A vector of probabilities.

alpha

A vector of confidence levels.

n

Number of observations.

lambda

A shape and scale and parameter.

chi, psi

Shape and scale parameters. Must be positive.

logvalue

If TRUE the logarithm of the density will be returned.

distr

Whether the ghyp-object specifies a return or a loss-distribution (see Details).

subdivisions

The number of subdivisions passed to integrate when computing the the distribution function pgig.

rel.tol

The relative accuracy requested from integrate.

abs.tol

The absolute accuracy requested from integrate.

method

Determines which method is used when calculating quantiles.

spline.points

The number of support points when computing the quantiles with the method “splines” instead of “integration”.

root.tol

The tolerance of uniroot.

func

The transformation function when computing the expected value. x is the expected value (default), log x returns the expected value of the logarithm of x, 1/x returns the expected value of the inverse of x and var returns the variance.

check.pars

If TRUE the parameters are checked first.

...

Arguments passed form ESgig to qgig.

Details

qgig computes the quantiles either by using the “integration” method where the root of the distribution function is solved or via “splines” which interpolates the distribution function and solves it with uniroot afterwards. The “integration” method is recommended when few quantiles are required. If more than approximately 20 quantiles are needed to be calculated the “splines” method becomes faster. The accuracy can be controlled with an adequate setting of the parameters rel.tol, abs.tol, root.tol and spline.points.

rgig relies on the C function with the same name kindly provided by Ester Pantaleo and Robert B. Gramacy.

Egig with func = "log x" uses grad from the R package numDeriv. See the package vignette for details regarding the expectation of GIG random variables.

Value

dgig gives the density,
pgig gives the distribution function,
qgig gives the quantile function,
ESgig gives the expected shortfall,
rgig generates random deviates and
Egig gives the expected value of either x, 1/x, log(x) or the variance if func equals var.

Author(s)

David Luethi and Ester Pantaleo

References

Dagpunar, J.S. (1989). An easily implemented generalised inverse Gaussian generator. Commun. Statist. -Simula., 18, 703–710.

Michael, J. R, Schucany, W. R, Haas, R, W. (1976). Generating random variates using transformations with multiple roots, The American Statistican, 30, 88–90.

See Also

fit.ghypuv, fit.ghypmv, integrate, uniroot, spline

Examples

1
2
3
4
5
6
7
8
9
dgig(1:40, lambda = 10, chi = 1, psi = 1)
qgig(1e-5, lambda = 10, chi = 1, psi = 1)

ESgig(c(0.19,0.3), lambda = 10, chi = 1, psi = 1, distr = "loss")
ESgig(alpha=c(0.19,0.3), lambda = 10, chi = 1, psi = 1, distr = "ret")

Egig(lambda = 10, chi = 1, psi = 1, func = "x")
Egig(lambda = 10, chi = 1, psi = 1, func = "var")
Egig(lambda = 10, chi = 1, psi = 1, func = "1/x")

Example output

Loading required package: numDeriv
Loading required package: gplots

Attaching package: 'gplots'

The following object is masked from 'package:stats':

    lowess

 [1] 1.017854e-09 4.058652e-07 1.028601e-05 8.662516e-05 4.013694e-04
 [6] 1.277222e-03 3.139139e-03 6.389523e-03 1.126445e-02 1.773343e-02
[11] 2.547732e-02 3.394288e-02 4.244752e-02 5.029911e-02 5.690051e-02
[16] 6.182046e-02 6.482518e-02 6.587466e-02 6.509325e-02 6.272601e-02
[21] 5.909098e-02 5.453489e-02 4.939724e-02 4.398448e-02 3.855432e-02
[26] 3.330887e-02 2.839460e-02 2.390695e-02 1.989775e-02 1.638384e-02
[31] 1.335568e-02 1.078530e-02 8.633089e-03 6.853261e-03 5.398022e-03
[36] 4.220558e-03 3.277017e-03 2.527684e-03 1.937542e-03 1.476391e-03
[1] 3.383629
[1] 21.95485 22.98326
[1] 11.95756 13.22362
[1] 20.05536
[1] 40.00038
[1] 0.05536417

ghyp documentation built on May 2, 2019, 6:09 p.m.