Density, distribution function, quantile function and
random generation for the normal inverse-Gaussian distribution
with parameters p, a and b.
Usage
dnig(x, delta, mu, nu, sigma, h = NULL, log = FALSE)
rnig(n, delta, mu, nu, sigma, h = NULL, seed = 0)
pnig(q, delta, mu, nu, sigma, h = NULL, lower.tail = TRUE, log.p = FALSE)
qnig(p, delta, mu, nu, sigma, h = NULL, lower.tail = TRUE, log.p = FALSE)Arguments
- x, q
vector of quantiles.
- delta
A numeric value for the location parameter.
- mu
A numeric value for the shift parameter.
- nu
A numeric value for the shape parameter.
- sigma
A numeric value for the scaling parameter.
- h
A numeric value for the additional parameter, see details.
- log, log.p
logical; if
TRUE, probabilities/densities \(p\) are returned as \(log(p)\).- n,
number of observations.
- seed
Seed for the random generation.
- lower.tail
logical; if
TRUE, probabilities are \(P[X\leq x]\), otherwise, \(P[X>x]\).- p
vector of probabilities.
Value
dnig gives the density, pnig gives the distribution function, qnig gives the quantile function, and rnig generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
The length of the result is determined by n for rnig.
Details
The normal inverse-Gaussian distribution has density given by $$f(x; \delta, \mu, \sigma, \nu) = \frac{e^{\nu+\mu(x-\delta)/\sigma^2}\sqrt{\nu\mu^2/\sigma^2+\nu^2}}{\pi\sqrt{\nu\sigma^2+(x-\delta)^2}} K_1(\sqrt{(\nu\sigma^2+(x-\delta)^2)(\mu^2/\sigma^4+\nu/\sigma^2)}),$$ where \(K_p\) is modified Bessel function of the second kind of order \(p\), \(x>0\), \(\nu>0\) and \(\mu,\delta, \sigma\in\mathbb{R}\). See Barndorff-Nielsen (1977, 1978 and 1997) for further details.
The additional parameter h is used when $$V\sim IG(\nu,\nu h^{2})$$. By the infinite divisibility, $$\frac{1}{h} V \sim IG(\nu h, \nu h)$$. Then $$\delta+\mu V + \sigma \sqrt{V} Z$$ has the distribution of $$NIG(\delta=-\mu h,\mu= \mu h, \sigma=\sigma \sqrt{h}, \nu=\nu h).$$
References
Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for the logarithm of particle size. Proceedings of the Royal Society of London.
Series A, Mathematical and Physical Sciences. The Royal Society. 353, 401–409. doi:10.1098/rspa.1977.0041
Barndorff-Nielsen, O. (1978) Hyperbolic Distributions and Distributions on Hyperbolae, Scandinavian Journal of Statistics. 5, 151–157.
Barndorff-Nielsen, O. (1997) Normal Inverse Gaussian Distributions and Stochastic Volatility Modelling, Scandinavian Journal of Statistics. 24, 1-13. doi:10.1111/1467-9469.00045
Examples
rnig(100, delta = 0, mu = 5, sigma = 1, nu = 1)
#> [1] 7.31503647 0.04058112 3.27735006 7.71065013 19.77075958 11.95745191
#> [7] 8.19849700 5.46087311 7.62786805 13.22062456 0.68668680 7.84514158
#> [13] 6.33765785 2.40410421 0.57149821 0.38046336 1.25901354 1.27783227
#> [19] 3.28152587 3.03062991 5.82244215 5.51904112 3.41942475 21.60174617
#> [25] 26.50450206 2.62356603 3.55735952 8.95254801 2.99704468 1.62441070
#> [31] 2.00314232 1.19275747 2.46925661 11.29787950 3.08426102 2.83375536
#> [37] 1.98533167 1.82605004 10.52569496 1.96131747 1.55003253 2.21060397
#> [43] 0.93459823 6.97753467 3.94338985 2.74008841 3.47948999 7.76374661
#> [49] 11.22308485 3.19717090 8.59603251 7.19544701 6.95831895 6.73555749
#> [55] 10.63498555 4.62185313 1.00755747 2.62536820 21.94362085 5.22743073
#> [61] 5.97379947 9.92566014 2.99668711 3.70735096 8.41012778 5.91270559
#> [67] 1.47186560 10.80104155 9.53687278 10.66135942 0.55154220 1.18353520
#> [73] 7.15046827 2.34327204 2.15714447 28.18603348 0.47452594 1.29015874
#> [79] 1.93383598 4.40108710 5.34101236 4.38586738 3.03420006 7.68669496
#> [85] 3.70687866 11.91186852 5.59103108 14.12049751 1.63058185 2.57406738
#> [91] 34.76774861 2.65877300 1.30812456 1.78764461 0.84913117 2.36196523
#> [97] 9.22742832 3.67404804 2.01295202 12.02443990
#> attr(,"V")
#> [1] 1.1409380 0.1489150 0.5396649 1.8034561 3.6146315 2.1668237 1.4811327
#> [8] 1.2100667 1.5464774 3.3843553 0.1810253 1.5438007 1.2802516 0.9565608
#> [15] 0.1651447 0.1421437 0.2247321 0.2230852 0.8263094 0.5623716 1.1542183
#> [22] 1.0144169 0.5820033 4.4522117 4.2592009 0.5891435 0.5188352 1.8512541
#> [29] 0.5143348 0.3324081 0.4997680 0.2961453 0.4705592 2.2255292 0.7552326
#> [36] 0.6034239 0.2731205 0.3431882 1.8245060 0.4527968 0.3995982 0.4380929
#> [43] 0.2300773 1.2458239 0.5308655 0.4617829 0.6370775 1.2447833 2.5199078
#> [50] 0.3508274 1.7077477 1.5175026 0.8856199 1.2210439 2.2919326 0.9704218
#> [57] 0.3829310 0.4712506 4.0252125 0.8269415 0.9631321 2.3094933 0.5512511
#> [64] 0.7753580 1.5017101 0.9361231 0.3233919 2.1631643 2.2815548 2.4662677
#> [71] 0.2046887 0.3907479 1.3763159 0.3908994 0.4166012 4.9679681 0.1374759
#> [78] 0.4081343 0.3801098 0.6798139 1.1634738 0.7481267 0.5745603 1.9032424
#> [85] 0.5043387 2.4216592 1.6521078 2.3150757 0.3249697 0.3472359 6.8136415
#> [92] 0.4760212 0.3634665 0.3110423 0.3407968 0.5432395 1.6173728 0.8293106
#> [99] 0.5346080 2.0983846
pnig(0.4, delta = 0, mu = 5, sigma = 1, nu = 1)
#> [1] 0.01597497
qnig(0.8, delta = 0, mu = 5, sigma = 1, nu = 1)
#> [1] 7.390234
plot(function(x){dnig(x, delta = 0, mu = 5, sigma = 1, nu = 1)}, main =
"Normal inverse-Gaussian density", ylab = "Probability density",
xlim = c(0,10))
