Last data update: 2014.03.03
R: Ratio of Bessel K Functions
Bessel K Ratio R Documentation
Ratio of Bessel K Functions
Description
Calculates the ratio of Bessel K functions of different orders, but
the same value of the argument.
Usage
besselRatio(x, nu, orderDiff, useExpScaled = 700)
Arguments
x
Numeric, >= 0 . Value at which the numerator and
denominator Bessel functions are evaluated.
nu
Numeric. The order of the Bessel function in the
denominator.
orderDiff
Numeric. The order of the numerator Bessel function
minus the order of the denominator Bessel function.
useExpScaled
Numeric, >= 0 . The smallest value of
x for which the ratio is calculated using the
exponentially-scaled Bessel function values.
Details
Uses the function besselK
to calculate the ratio of two
modified Bessel function of the third kind whose orders are
different. The calculation of Bessel functions will underflow if the
value of x is greater than around 740. To avoid underflow the
exponentially-scaled Bessel functions can be returned by
besselK
. The ratio is actually unaffected by exponential
scaling since the scaling cancels across numerator and denominator.
The Bessel function ratio is useful in calculating moments of the
generalized inverse Gaussian distribution, and hence also for the
moments of the hyperbolic and generalized hyperbolic distributions.
Value
The ratio
K_(nu+k)(x)/K_nu(x)
of two modified Bessel functions of the third kind whose orders differ
by k .
Author(s)
David Scott d.scott@auckland.ac.nz
See Also
besselK
, gigMom
Examples
nus <- c(0:5, 10, 20)
x <- seq(1, 4, length.out = 11)
k <- 3
raw <- matrix(nrow = length(nus), ncol = length(x))
scaled <- matrix(nrow = length(nus), ncol = length(x))
compare <- matrix(nrow = length(nus), ncol = length(x))
for (i in 1:length(nus)){
for (j in 1:length(x)) {
raw[i,j] <- besselRatio(x[j], nus[i],
orderDiff = k)
scaled[i,j] <- besselRatio(x[j], nus[i],
orderDiff = k, useExpScaled = 1)
compare[i,j] <- raw[i,j]/scaled[i,j]
}
}
raw
scaled
compare
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(DistributionUtils)
Loading required package: RUnit
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/DistributionUtils/besselRatio.Rd_%03d_medium.png", width=480, height=480)
> ### Name: Bessel K Ratio
> ### Title: Ratio of Bessel K Functions
> ### Aliases: besselRatio
> ### Keywords: math
>
> ### ** Examples
>
> nus <- c(0:5, 10, 20)
> x <- seq(1, 4, length.out = 11)
> k <- 3
>
> raw <- matrix(nrow = length(nus), ncol = length(x))
> scaled <- matrix(nrow = length(nus), ncol = length(x))
> compare <- matrix(nrow = length(nus), ncol = length(x))
>
> for (i in 1:length(nus)){
+ for (j in 1:length(x)) {
+ raw[i,j] <- besselRatio(x[j], nus[i],
+ orderDiff = k)
+ scaled[i,j] <- besselRatio(x[j], nus[i],
+ orderDiff = k, useExpScaled = 1)
+ compare[i,j] <- raw[i,j]/scaled[i,j]
+ }
+ }
> raw
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 16.86663 10.75385 7.781137 6.090468 5.024655 4.302128
[2,] 73.48710 39.35525 24.822473 17.380739 13.074196 10.355893
[3,] 222.15162 109.48831 64.098882 41.995961 29.773284 22.368514
[4,] 514.53360 244.54113 137.964988 87.165108 59.673423 43.368998
[5,] 999.42586 467.03943 258.597043 160.171259 107.450155 76.520698
[6,] 1724.70940 798.93325 437.859195 268.144833 177.715991 124.972350
[7,] 10633.28765 4862.90579 2623.886703 1578.095601 1024.973207 705.066531
[8,] 74052.62238 33747.89311 18129.755109 10846.870001 7002.415905 4783.910099
[,7] [,8] [,9] [,10] [,11]
[1,] 3.785224 3.399798 3.102843 2.867909 2.677938
[2,] 8.525505 7.230002 6.276125 5.550945 4.984885
[3,] 17.564024 14.275849 11.927487 10.191042 8.869535
[4,] 33.006241 26.053230 21.180509 17.641581 14.993686
[5,] 57.081406 44.185346 35.249374 28.831590 24.082062
[6,] 92.029179 70.317805 55.375514 44.718344 36.886643
[7,] 507.122749 377.998297 290.107405 228.152598 183.181231
[8,] 3414.690278 2524.043094 1919.703872 1495.154973 1188.123170
> scaled
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 16.86663 10.75385 7.781137 6.090468 5.024655 4.302128
[2,] 73.48710 39.35525 24.822473 17.380739 13.074196 10.355893
[3,] 222.15162 109.48831 64.098882 41.995961 29.773284 22.368514
[4,] 514.53360 244.54113 137.964988 87.165108 59.673423 43.368998
[5,] 999.42586 467.03943 258.597043 160.171259 107.450155 76.520698
[6,] 1724.70940 798.93325 437.859195 268.144833 177.715991 124.972350
[7,] 10633.28765 4862.90579 2623.886703 1578.095601 1024.973207 705.066531
[8,] 74052.62238 33747.89311 18129.755109 10846.870001 7002.415905 4783.910099
[,7] [,8] [,9] [,10] [,11]
[1,] 3.785224 3.399798 3.102843 2.867909 2.677938
[2,] 8.525505 7.230002 6.276125 5.550945 4.984885
[3,] 17.564024 14.275849 11.927487 10.191042 8.869535
[4,] 33.006241 26.053230 21.180509 17.641581 14.993686
[5,] 57.081406 44.185346 35.249374 28.831590 24.082062
[6,] 92.029179 70.317805 55.375514 44.718344 36.886643
[7,] 507.122749 377.998297 290.107405 228.152598 183.181231
[8,] 3414.690278 2524.043094 1919.703872 1495.154973 1188.123170
> compare
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11]
[1,] 1 1 1 1 1 1 1 1 1 1 1
[2,] 1 1 1 1 1 1 1 1 1 1 1
[3,] 1 1 1 1 1 1 1 1 1 1 1
[4,] 1 1 1 1 1 1 1 1 1 1 1
[5,] 1 1 1 1 1 1 1 1 1 1 1
[6,] 1 1 1 1 1 1 1 1 1 1 1
[7,] 1 1 1 1 1 1 1 1 1 1 1
[8,] 1 1 1 1 1 1 1 1 1 1 1
>
>
>
>
>
>
> dev.off()
null device
1
>