Title: | The Hyperbolic Distribution |
---|---|
Description: | Maintenance has been discontinued for this package. It has been superseded by 'GeneralizedHyperbolic'. 'GeneralizedHyperbolic' includes all the functionality of 'HyperbolicDist' and more and is based on a more rational design. 'HyperbolicDist' provides functions for the hyperbolic and related distributions. Density, distribution and quantile functions and random number generation are provided for the hyperbolic distribution, the generalized hyperbolic distribution, the generalized inverse Gaussian distribution and the skew-Laplace distribution. Additional functionality is provided for the hyperbolic distribution, including fitting of the hyperbolic to data. |
Authors: | David Scott <[email protected]> |
Maintainer: | David Scott <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.6-5 |
Built: | 2024-11-18 05:39:00 UTC |
Source: | https://github.com/cran/HyperbolicDist |
Calculates the ratio of Bessel K functions of different orders
besselRatio(x, nu, orderDiff, useExpScaled = 700)
besselRatio(x, nu, orderDiff, useExpScaled = 700)
x |
Numeric, |
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, |
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 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.
The ratio
of two modified Bessel functions of the third kind whose orders differ
by .
David Scott [email protected]
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
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
Functions used to calculate the mean, variance, skewness and kurtosis of a hyperbolic distribution. Not expected to be called directly by users.
RLambda(zeta, lambda = 1) SLambda(zeta, lambda = 1) MLambda(zeta, lambda = 1) WLambda1(zeta, lambda = 1) WLambda2(zeta, lambda = 1) WLambda3(zeta, lambda = 1) WLambda4(zeta, lambda = 1) gammaLambda1(hyperbPi, zeta, lambda = 1) gammaLambda1(hyperbPi, zeta, lambda = 1)
RLambda(zeta, lambda = 1) SLambda(zeta, lambda = 1) MLambda(zeta, lambda = 1) WLambda1(zeta, lambda = 1) WLambda2(zeta, lambda = 1) WLambda3(zeta, lambda = 1) WLambda4(zeta, lambda = 1) gammaLambda1(hyperbPi, zeta, lambda = 1) gammaLambda1(hyperbPi, zeta, lambda = 1)
hyperbPi |
Value of the parameter |
zeta |
Value of the parameter |
lambda |
Parameter related to order of Bessel functions. |
The functions RLambda
and SLambda
are used in the calculation of the mean and variance. They are
functions of the Bessel functions of the third kind,
implemented in R as besselK
. The other functions are
used in calculation of higher moments. See Barndorff-Nielsen, O. and
Blaesild, P (1981) for details of the calculations.
The parameterisation of the hyperbolic distribution used for this
and other components of the HyperbolicDist
package is the
one. See
hyperbChangePars
to
transfer between parameterizations.
David Scott [email protected], Richard Trendall, Thomas Tran
Barndorff-Nielsen, O. and Blæsild, P (1981). Hyperbolic distributions and ramifications: contributions to theory and application. In Statistical Distributions in Scientific Work, eds., Taillie, C., Patil, G. P., and Baldessari, B. A., Vol. 4, pp. 19–44. Dordrecht: Reidel.
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
dhyperb
,
hyperbMean
,hyperbChangePars
,
besselK
Density function, cumulative distribution function, quantile function
and random number generation for the generalized inverse Gaussian
distribution with parameter vector Theta
. Utility routines are
included for the derivative of the density function and to find
suitable break points for use in determining the distribution function.
dgig(x, Theta, KOmega = NULL) pgig(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qgig(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rgig(n, Theta) rgig1(n, Theta) ddgig(x, Theta, KOmega = NULL, ...) gigBreaks (Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
dgig(x, Theta, KOmega = NULL) pgig(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qgig(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rgig(n, Theta) rgig1(n, Theta) ddgig(x, Theta, KOmega = NULL, ...) gigBreaks (Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
x , q
|
Vector of quantiles. |
p |
Vector of probabilities. |
n |
Number of observations to be generated. |
Theta |
Parameter vector taking the form |
KOmega |
Sets the value of the Bessel function in the density or derivative of the density. See Details. |
small |
Size of a small difference between the distribution function and zero or one. See Details. |
tiny |
Size of a tiny difference between the distribution function and zero or one. See Details. |
deriv |
Value between 0 and 1. Determines the point where the derivative becomes substantial, compared to its maximum value. See Details. |
accuracy |
Uses accuracy calculated by |
subdivisions |
The maximum number of subdivisions used to integrate the density returning the distribution function. |
nInterpol |
The number of points used in qhyperb for cubic spline
interpolation (see |
... |
Passes arguments to |
The generalized inverse Gaussian distribution has density
for , where
is the
modified Bessel function of the third kind with order
.
The generalized inverse Gaussian distribution is investigated in detail in Jörgensen (1982).
Use gigChangePars
to convert from the
,
, or
parameterisations to the
, parameterisation used above.
pgig
breaks the real line into eight regions in order to
determine the integral of dgig
. The break points determining
the regions are found by gigBreaks
, based on the values of
small
, tiny
, and deriv
. In the extreme tails of
the distribution where the probability is tiny
according to
gigCalcRange
, the probability is taken to be zero. For the
generalized inverse Gaussian distribution the leftmost breakpoint is
not affected by the value of tiny
but is always taken as 0. In
the inner part of the distribution, the range is divided in 6 regions,
3 above the mode, and 3 below. On each side of the mode, there are two
break points giving the required three regions. The outer break point
is where the probability in the tail has the value given by the
variable small
. The inner break point is where the derivative
of the density function is deriv
times the maximum value of the
derivative on that side of the mode. In each of the 6 inner regions
the numerical integration routine safeIntegrate
(which
is a wrapper for integrate
) is used to integrate the
density dgig
.
qgig
use the breakup of the real line into the same 8
regions as pgig
. For quantiles which fall in the 2 extreme
regions, the quantile is returned as -Inf
or Inf
as
appropriate. In the 6 inner regions splinefun
is used to fit
values of the distribution function generated by pgig
. The
quantiles are then found using the uniroot
function.
pgig
and qgig
may generally be expected to be accurate
to 5 decimal places. Unfortunately, when lambda
is less than
-0.5, the accuracy may be as little as 3 decimal places.
Generalized inverse Gaussian observations are obtained via the algorithm of Dagpunar (1989).
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 . An estimate of the
accuracy of the approximation to the distribution function may be
found by setting
accuracy = TRUE
in the call to phyperb
which then returns a list with components value
and
error
.
ddgig
gives the derivative of dgig
.
gigBreaks
returns a list with components:
xTiny |
Takes value 0 always. |
xSmall |
Value such that probability to the left is less than
|
lowBreak |
Point to the left of the mode such that the
derivative of the density is |
highBreak |
Point to the right of the mode such that the
derivative of the density is |
xLarge |
Value such that probability to the right is less than
|
xHuge |
Value such that probability to the right is less than
|
modeDist |
The mode of the given generalized inverse Gaussian distribution. |
David Scott [email protected], Richard Trendall, and Melanie Luen.
Dagpunar, J.S. (1989). An easily implemented generalised inverse Gaussian generator. Commun. Statist. -Simula., 18, 703–710.
Jörgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
safeIntegrate
, integrate
for its
shortfalls, splinefun
, uniroot
and
gigChangePars
for changing parameters to the
parameterisation,
dghyp
for
the generalized hyperbolic distribution.
Theta <- c(1,2,3) gigRange <- gigCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Density of the\n Generalized Inverse Gaussian") curve(pgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Distribution Function of the\n Generalized Inverse Gaussian") dataVector <- rgig(500, Theta) curve(dgig(x, Theta), 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, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Density of the\n Generalized Inverse Gaussian") curve(ddgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Derivative of the Density\n of the Generalized Inverse Gaussian") par(mfrow = c(1,1)) gigRange <- gigCalcRange(Theta, tol = 10^(-6)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) bks <- gigBreaks(Theta) abline(v = bks)
Theta <- c(1,2,3) gigRange <- gigCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Density of the\n Generalized Inverse Gaussian") curve(pgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Distribution Function of the\n Generalized Inverse Gaussian") dataVector <- rgig(500, Theta) curve(dgig(x, Theta), 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, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Density of the\n Generalized Inverse Gaussian") curve(ddgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) title("Derivative of the Density\n of the Generalized Inverse Gaussian") par(mfrow = c(1,1)) gigRange <- gigCalcRange(Theta, tol = 10^(-6)) curve(dgig(x, Theta), from = gigRange[1], to = gigRange[2], n = 1000) bks <- gigBreaks(Theta) abline(v = bks)
Density function, distribution function, quantiles and
random number generation for the generalized hyperbolic distribution
with parameter vector Theta
. Utility routines are included for
the derivative of the density function and to find suitable break
points for use in determining the distribution function.
dghyp(x, Theta) pghyp(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qghyp(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rghyp(n, Theta) ddghyp(x, Theta) ghypBreaks(Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
dghyp(x, Theta) pghyp(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qghyp(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rghyp(n, Theta) ddghyp(x, Theta) ghypBreaks(Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
x , q
|
Vector of quantiles. |
p |
Vector of probabilities. |
n |
Number of observations to be generated. |
Theta |
Parameter vector taking the form
|
small |
Size of a small difference between the distribution function and zero or one. See Details. |
tiny |
Size of a tiny difference between the distribution function and zero or one. See Details. |
deriv |
Value between 0 and 1. Determines the point where the derivative becomes substantial, compared to its maximum value. See Details. |
accuracy |
Uses accuracy calculated by~ |
subdivisions |
The maximum number of subdivisions used to integrate the density returning the distribution function. |
nInterpol |
The number of points used in qghyp for cubic spline
interpolation (see |
... |
Passes arguments to |
The generalized hyperbolic distribution has density
where is the modified Bessel function of the
third kind with order
, and
Use ghypChangePars
to convert from the
,
, or
parameterisations
to the
parameterisation used
above.
pghyp
breaks the real line into eight regions in order to
determine the integral of dghyp
. The break points determining
the regions are found by ghypBreaks
, based on the values of
small
, tiny
, and deriv
. In the extreme tails of
the distribution where the probability is tiny
according to
ghypCalcRange
, the probability is taken to be zero. In the
inner part of the distribution, the range is divided in 6 regions, 3
above the mode, and 3 below. On each side of the mode, there are two
break points giving the required three regions. The outer break point
is where the probability in the tail has the value given by the variable
small
. The inner break point is where the derivative of the
density function is deriv
times the maximum value of the
derivative on that side of the mode. In each of the 6 inner regions
the numerical integration routine safeIntegrate
(which
is a wrapper for integrate
) is used to integrate the
density dghyp
.
qghyp
use the breakup of the real line into the same 8
regions as pghyp
. For quantiles which fall in the 2 extreme
regions, the quantile is returned as -Inf
or Inf
as
appropriate. In the 6 inner regions splinefun
is used to fit
values of the distribution function generated by pghyp
. The
quantiles are then found using the uniroot
function.
pghyp
and qghyp
may generally be expected to be
accurate to 5 decimal places.
The generalized hyperbolic distribution is discussed in Bibby and
Sörenson (2003). It can be represented as a particular
mixture of the normal distribution where the mixing distribution is the
generalized inverse Gaussian. rghyp
uses this representation
to generate observations from the generalized hyperbolic
distribution. Generalized inverse Gaussian observations are obtained
via the algorithm of Dagpunar (1989) which is implemented in
rgig
.
dghyp
gives the density, pghyp
gives the distribution
function, qghyp
gives the quantile function and rghyp
generates random variates. An estimate of the accuracy of the
approximation to the distribution function may be found by setting
accuracy=TRUE
in the call to pghyp
which then returns
a list with components value
and error
.
ddghyp
gives the derivative of dghyp
.
ghypBreaks
returns a list with components:
xTiny |
Value such that probability to the left is less than
|
xSmall |
Value such that probability to the left is less than
|
lowBreak |
Point to the left of the mode such that the
derivative of the density is |
highBreak |
Point to the right of the mode such that the
derivative of the density is |
xLarge |
Value such that probability to the right is less than
|
xHuge |
Value such that probability to the right is less than
|
modeDist |
The mode of the given generalized hyperbolic distribution. |
David Scott [email protected], Richard Trendall
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Bibby, B. M. and Sörenson, M. (2003). Hyperbolic processes in finance. In Handbook of Heavy Tailed Distributions in Finance, ed., Rachev, S. T. pp. 212–248. Elsevier Science B.~V.
Dagpunar, J.S. (1989). An easily implemented generalised inverse Gaussian generator Commun. Statist. -Simula., 18, 703–710.
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
dhyperb
for the hyperbolic distribution,
dgig
for the generalized inverse Gaussian distribution
safeIntegrate
, integrate
for its
shortfalls, splinefun
,
uniroot
and ghypChangePars
for
changing parameters to the
parameterisation
Theta <- c(1/2,3,1,1,0) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Density of the\n Generalized Hyperbolic Distribution") curve(pghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Distribution Function of the\n Generalized Hyperbolic Distribution") dataVector <- rghyp(500, Theta) curve(dghyp(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram of the\n Generalized Hyperbolic Distribution") logHist(dataVector, main = "Log-Density and Log-Histogramof the\n Generalized Hyperbolic Distribution") curve(log(dghyp(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Density of the\n Generalized Hyperbolic Distribution") curve(ddghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Derivative of the Density of the\n Generalized Hyperbolic Distribution") par(mfrow = c(1,1)) ghypRange <- ghypCalcRange(Theta, tol = 10^(-6)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) bks <- ghypBreaks(Theta) abline(v = bks)
Theta <- c(1/2,3,1,1,0) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Density of the\n Generalized Hyperbolic Distribution") curve(pghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Distribution Function of the\n Generalized Hyperbolic Distribution") dataVector <- rghyp(500, Theta) curve(dghyp(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram of the\n Generalized Hyperbolic Distribution") logHist(dataVector, main = "Log-Density and Log-Histogramof the\n Generalized Hyperbolic Distribution") curve(log(dghyp(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Density of the\n Generalized Hyperbolic Distribution") curve(ddghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) title("Derivative of the Density of the\n Generalized Hyperbolic Distribution") par(mfrow = c(1,1)) ghypRange <- ghypCalcRange(Theta, tol = 10^(-6)) curve(dghyp(x, Theta), from = ghypRange[1], to = ghypRange[2], n = 1000) bks <- ghypBreaks(Theta) abline(v = bks)
qqghyp
produces a generalized hyperbolic Q-Q plot of the values in
y
.
ppghyp
produces a generalized hyperbolic P-P (percent-percent) or
probability plot of the values in y
.
Graphical parameters may be given as arguments to qqghyp
,
and ppghyp
.
qqghyp(y, Theta, main = "Generalized Hyperbolic Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppghyp(y, Theta, main = "Generalized Hyperbolic P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
qqghyp(y, Theta, main = "Generalized Hyperbolic Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppghyp(y, Theta, main = "Generalized Hyperbolic P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
y |
The data sample. |
Theta |
Parameters of the generalized hyperbolic distribution. |
xlab , ylab , main
|
Plot labels. |
plot.it |
Logical. Should the result be plotted? |
line |
Add line through origin with unit slope. |
... |
Further graphical parameters. |
For qqghyp
and ppghyp
, a list with components:
x |
The x coordinates of the points that are to be plotted. |
y |
The y coordinates of the points that are to be plotted. |
Wilk, M. B. and Gnanadesikan, R. (1968) Probability plotting methods for the analysis of data. Biometrika. 55, 1–17.
par(mfrow = c(1,2)) y <- rghyp(200, c(2,2,1,2,2)) qqghyp(y, c(2,2,1,2,2),line = FALSE) abline(0, 1, col = 2) ppghyp(y, c(2,2,1,2,2))
par(mfrow = c(1,2)) y <- rghyp(200, c(2,2,1,2,2)) qqghyp(y, c(2,2,1,2,2),line = FALSE) abline(0, 1, col = 2) ppghyp(y, c(2,2,1,2,2))
Given the parameter vector Theta of a generalized hyperbolic distribution,
this function determines the range outside of which the density
function is negligible, to a specified tolerance. The parameterization used
is the one (see
dghyp
). To use another parameterization, use
ghypChangePars
.
ghypCalcRange(Theta, tol = 10^(-5), density = TRUE, ...)
ghypCalcRange(Theta, tol = 10^(-5), density = TRUE, ...)
Theta |
Value of parameter vector specifying the hyperbolic distribution. |
tol |
Tolerance. |
density |
Logical. If |
... |
Extra arguments for calls to |
The particular generalized hyperbolic distribution being considered is
specified by the value of the parameter value Theta
.
If density = TRUE
, the function gives a range, outside of which
the density is less than the given tolerance. Useful for plotting the
density. Also used in determining break points for the separate
sections over which numerical integration is used to determine the
distribution function. The points are found by using
uniroot
on the density function.
If density = FALSE
, the function returns the message:
"Distribution function bounds not yet implemented
".
A two-component vector giving the lower and upper ends of the range.
David Scott [email protected]
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Theta <- c(1,5,3,1,0) maxDens <- dghyp(ghypMode(Theta), Theta) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)*maxDens) ghypRange curve(dghyp(x, Theta), ghypRange[1], ghypRange[2]) ## Not run: ghypCalcRange(Theta, tol = 10^(-3), density = FALSE)
Theta <- c(1,5,3,1,0) maxDens <- dghyp(ghypMode(Theta), Theta) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)*maxDens) ghypRange curve(dghyp(x, Theta), ghypRange[1], ghypRange[2]) ## Not run: ghypCalcRange(Theta, tol = 10^(-3), density = FALSE)
This function interchanges between the following 4 parameterizations of the generalized hyperbolic distribution:
1.
2.
3.
4.
These are the parameterizations given in Prause (1999)
ghypChangePars(from, to, Theta, noNames = FALSE)
ghypChangePars(from, to, Theta, noNames = FALSE)
from |
The set of parameters to change from. |
to |
The set of parameters to change to. |
Theta |
"from" parameter vector consisting of 5 numerical elements. |
noNames |
Logical. When |
In the 4 parameterizations, the following must be positive:
1.
2.
3.
4.
Furthermore, note that in the first parameterization
must be greater than the absolute value of
; in the third parameterization,
must be less than one, and the absolute value of
must
be less than
; and in the fourth parameterization,
must be greater than the absolute value of
.
A numerical vector of length 5 representing Theta
in the
to
parameterization.
David Scott [email protected], Jennifer Tso, Richard Trendall
Barndorff-Nielsen, O. and Blæsild, P. (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
Theta1 <- c(2,2,1,3,0) # Parameterization 1 Theta2 <- ghypChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 ghypChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
Theta1 <- c(2,2,1,3,0) # Parameterization 1 Theta2 <- ghypChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 ghypChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
This function can be used to calculate raw moments, mu moments, central moments and moments about any other given location for the generalized hyperbolic distribution.
ghypMom(order, Theta, momType = "raw", about = 0)
ghypMom(order, Theta, momType = "raw", about = 0)
order |
Numeric. The order of the moment to be calculated. Not permitted to be a vector. Must be a positive whole number except for moments about zero. |
Theta |
Numeric. The parameter vector specifying the GIG
distribution. Of the form |
momType |
Common types of moments to be calculated, default is "raw". See Details. |
about |
Numeric. The point around which the moment is to be calculated, default is 0. See Details. |
Checking whether order
is a whole number is carried out using
the function is.wholenumber
.
momType
can be either "raw" (moments about zero), "mu" (moments
about mu), or "central" (moments about mean). If one of these moment
types is specified, then there is no need to specify the about
value. For moments about any other location, the about
value
must be specified. In the case that both momType
and
about
are specified and contradicting, the function will always
calculate the moments based on about
rather than
momType
.
To calculate moments of the generalized hyperbolic distribution, the
function first calculates mu moments by the formula defined below and
then transforms mu moments to central moments or raw moments or
moments about any other location as required by calling
momChangeAbout
.
The mu moments are obtained from the recursion formula given in Scott, Würtz and Tran (2008).
The moment specified.
David Scott [email protected]
Scott, D. J., Würtz, D. and Tran, T. T. (2008) Moments of the Generalized Hyperbolic Distribution. Preprint.
ghypChangePars
, is.wholenumber
,
momChangeAbout
, momIntegrated
,
ghypMean
, ghypVar
, ghypSkew
,
ghypKurt
.
Theta <- c(2,2,1,2,1) mu <- Theta[5] ### mu moments (m1 <- ghypMean(Theta)) m1 - mu ghypMom(1, Theta, momType = "mu") momIntegrated("ghyp", order = 1, param = Theta, about = mu) ghypMom(2, Theta, momType = "mu") momIntegrated("ghyp", order = 2, param = Theta, about = mu) ghypMom(10, Theta, momType = "mu") momIntegrated("ghyp", order = 10, param = Theta, about = mu) ### raw moments ghypMean(Theta) ghypMom(1, Theta, momType = "raw") momIntegrated("ghyp", order = 1, param = Theta, about = 0) ghypMom(2, Theta, momType = "raw") momIntegrated("ghyp", order = 2, param = Theta, about = 0) ghypMom(10, Theta, momType = "raw") momIntegrated("ghyp", order = 10, param = Theta, about = 0) ### central moments ghypMom(1, Theta, momType = "central") momIntegrated("ghyp", order = 1, param = Theta, about = m1) ghypVar(Theta) ghypMom(2, Theta, momType = "central") momIntegrated("ghyp", order = 2, param = Theta, about = m1) ghypMom(10, Theta, momType = "central") momIntegrated("ghyp", order = 10, param = Theta, about = m1)
Theta <- c(2,2,1,2,1) mu <- Theta[5] ### mu moments (m1 <- ghypMean(Theta)) m1 - mu ghypMom(1, Theta, momType = "mu") momIntegrated("ghyp", order = 1, param = Theta, about = mu) ghypMom(2, Theta, momType = "mu") momIntegrated("ghyp", order = 2, param = Theta, about = mu) ghypMom(10, Theta, momType = "mu") momIntegrated("ghyp", order = 10, param = Theta, about = mu) ### raw moments ghypMean(Theta) ghypMom(1, Theta, momType = "raw") momIntegrated("ghyp", order = 1, param = Theta, about = 0) ghypMom(2, Theta, momType = "raw") momIntegrated("ghyp", order = 2, param = Theta, about = 0) ghypMom(10, Theta, momType = "raw") momIntegrated("ghyp", order = 10, param = Theta, about = 0) ### central moments ghypMom(1, Theta, momType = "central") momIntegrated("ghyp", order = 1, param = Theta, about = m1) ghypVar(Theta) ghypMom(2, Theta, momType = "central") momIntegrated("ghyp", order = 2, param = Theta, about = m1) ghypMom(10, Theta, momType = "central") momIntegrated("ghyp", order = 10, param = Theta, about = m1)
Given the parameter vector Theta of a generalized inverse Gaussian
distribution, this function determines the range outside of which the density
function is negligible, to a specified tolerance. The parameterization
used is the one (see
dgig
). To use another parameterization, use
gigChangePars
.
gigCalcRange(Theta, tol = 10^(-5), density = TRUE, ...)
gigCalcRange(Theta, tol = 10^(-5), density = TRUE, ...)
Theta |
Value of parameter vector specifying the generalized inverse Gaussian distribution. |
tol |
Tolerance. |
density |
Logical. If |
... |
Extra arguments for calls to |
The particular generalized inverse Gaussian distribution being
considered is specified by the value of the parameter value
Theta
.
If density = TRUE
, the function gives a range, outside of which
the density is less than the given tolerance. Useful for plotting the
density. Also used in determining break points for the separate
sections over which numerical integration is used to determine the
distribution function. The points are found by using
uniroot
on the density function.
If density = FALSE
, the function returns the message:
"Distribution function bounds not yet implemented
".
A two-component vector giving the lower and upper ends of the range.
David Scott [email protected]
Jörgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
Theta <- c(-0.5,5,2.5) maxDens <- dgig(gigMode(Theta), Theta) gigRange <- gigCalcRange(Theta, tol = 10^(-3)*maxDens) gigRange curve(dgig(x, Theta), gigRange[1], gigRange[2]) ## Not run: gigCalcRange(Theta, tol = 10^(-3), density = FALSE)
Theta <- c(-0.5,5,2.5) maxDens <- dgig(gigMode(Theta), Theta) gigRange <- gigCalcRange(Theta, tol = 10^(-3)*maxDens) gigRange curve(dgig(x, Theta), gigRange[1], gigRange[2]) ## Not run: gigCalcRange(Theta, tol = 10^(-3), density = FALSE)
This function interchanges between the following 4 parameterizations of the generalized inverse Gaussian distribution:
1.
2.
3.
4.
See Jörgensen (1982) and Dagpunar (1989)
gigChangePars(from, to, Theta, noNames = FALSE)
gigChangePars(from, to, Theta, noNames = FALSE)
from |
The set of parameters to change from. |
to |
The set of parameters to change to. |
Theta |
“ |
noNames |
Logical. When |
The range of is the whole real line.
In each parameterization, the other two parameters must take positive
values.
A numerical vector of length 3 representing Theta
in the
“to
” parameterization.
David Scott [email protected]
Jörgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
Dagpunar, J. S. (1989). An easily implemented generalised inverse Gaussian generator, Commun. Statist.—Simula., 18, 703–710.
Theta1 <- c(-0.5,5,2.5) # Parameterisation 1 Theta2 <- gigChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 gigChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
Theta1 <- c(-0.5,5,2.5) # Parameterisation 1 Theta2 <- gigChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 gigChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
Given a putative set of parameters for the generalized inverse Gaussian distribution, the functions checks if they are in the correct range, and if they correspond to the boundary cases.
gigCheckPars(Theta, ...)
gigCheckPars(Theta, ...)
Theta |
Numeric. Putative parameter values for a generalized inverse Gaussian distribution. |
... |
Further arguments for calls to |
The vector Theta
takes the form c(lambda,chi,psi)
.
If either chi
or psi
is negative, an error is returned.
If chi
is 0 (to within tolerance allowed by all.equal
)
then psi
and lambda
must be positive or an error is
returned. If these conditions are satisfied, the distribution is
identified as a gamma distribution.
If psi
is 0 (to within tolerance allowed by all.equal
)
then chi
must be positive and lambda
must be negative or
an error is returned. If these conditions are satisfied, the
distribution is identified as an inverse gamma distribution.
If both chi
and psi
are positive, then the distribution
is identified as a normal generalized inverse Gaussian distribution.
A list with components:
case |
Whichever of |
errMessage |
An appropriate error message if an error was found,
the empty string |
David Scott [email protected]
Paolella, Marc S. (2007) Intermediate Probability: A Computational Approach, Chichester: Wiley
gigCheckPars(c(-0.5,5,2.5)) # normal gigCheckPars(c(0.5,-5,2.5)) # error gigCheckPars(c(0.5,5,-2.5)) # error gigCheckPars(c(0.5,-5,-2.5)) # error gigCheckPars(c(0.5,0,2.5)) # gamma gigCheckPars(c(-0.5,0,2.5)) # error gigCheckPars(c(0.5,0,0)) # error gigCheckPars(c(-0.5,0,0)) # error gigCheckPars(c(0.5,5,0)) # error gigCheckPars(c(-0.5,5,0)) # invgamma
gigCheckPars(c(-0.5,5,2.5)) # normal gigCheckPars(c(0.5,-5,2.5)) # error gigCheckPars(c(0.5,5,-2.5)) # error gigCheckPars(c(0.5,-5,-2.5)) # error gigCheckPars(c(0.5,0,2.5)) # gamma gigCheckPars(c(-0.5,0,2.5)) # error gigCheckPars(c(0.5,0,0)) # error gigCheckPars(c(-0.5,0,0)) # error gigCheckPars(c(0.5,5,0)) # error gigCheckPars(c(-0.5,5,0)) # invgamma
Functions to calculate raw moments and moments about a given location for the generalized inverse Gaussian (GIG) distribution, including the gamma and inverse gamma distributions as special cases.
gigRawMom(order, Theta) gigMom(order, Theta, about = 0) gammaRawMom(order, shape = 1, rate = 1, scale = 1/rate)
gigRawMom(order, Theta) gigMom(order, Theta, about = 0) gammaRawMom(order, shape = 1, rate = 1, scale = 1/rate)
order |
Numeric. The order of the moment to be calculated. Not permitted to be a vector. Must be a positive whole number except for moments about zero. |
Theta |
Numeric. The parameter vector specifying the GIG
distribution. Of the form |
about |
Numeric. The point around which the moment is to be calculated. |
shape |
Numeric. The shape parameter, must be non-negative, not permitted to be a vector. |
scale |
Numeric. The scale parameter, must be positive, not permitted to be a vector. |
rate |
Numeric. The rate parameter, an alternative way to specify the scale. |
The vector Theta
of parameters is examined using
gigCheckPars
to see if the parameters are valid for the GIG
distribution and if they correspond to the special cases which are the
gamma and inverse gamma distributions. Checking of special cases and
valid parameter vector values is carried out using the function
gigCheckPars
. Checking whether order
is a whole number is carried out using the function
is.wholenumber
.
Raw moments (moments about zero) are calculated using the
functions gigRawMom
or gammaRawMom
. For moments not
about zero, the function momChangeAbout
is used to
derive moments about another point from raw moments. Note that raw moments
of the inverse gamma distribution can be obtained from the raw moments
of the gamma distribution because of the relationship between the two
distributions. An alternative implementation of raw moments of the gamma
and inverse gamma distributions may be found in the package
actuar and these may be faster since they are written in C.
To calculate the raw moments of the GIG distribution it is convenient to
use the alternative parameterization of the GIG in terms of
and
, given as parameterization 3
in
gigChangePars
. Then the raw moment of the GIG
distribution of order is given by
where is the modified Bessel function of
the third kind of order
.
The raw moment of the gamma distribution of order with
shape parameter
and rate parameter
is given by
The raw moment of order of the inverse gamma distribution
with shape parameter
and rate parameter
is the raw moment of order
of the gamma
distribution with shape parameter
and rate parameter
.
The moment specified. In the case of raw moments, Inf
is
returned if the moment is infinite.
David Scott [email protected]
Paolella, Marc S. (2007) Intermediate Probability: A Computational Approach, Chichester: Wiley
gigCheckPars
, gigChangePars
,
is.wholenumber
, momChangeAbout
,
momIntegrated
, gigMean
,
gigVar
, gigSkew
, gigKurt
.
### Raw moments of the generalized inverse Gaussian distribution Theta <- c(-0.5,5,2.5) gigRawMom(1, Theta) momIntegrated("gig", order = 1, param = Theta, about = 0) gigRawMom(2, Theta) momIntegrated("gig", order = 2, param = Theta, about = 0) gigRawMom(10, Theta) momIntegrated("gig", order = 10, param = Theta, about = 0) gigRawMom(2.5, Theta) ### Moments of the generalized inverse Gaussian distribution Theta <- c(-0.5,5,2.5) (m1 <- gigRawMom(1, Theta)) gigMom(1, Theta) gigMom(2, Theta, m1) (m2 <- momIntegrated("gig", order = 2, param = Theta, about = m1)) gigMom(1, Theta, m1) gigMom(3, Theta, m1) momIntegrated("gig", order = 3, param = Theta, about = m1) ### Raw moments of the gamma distribution shape <- 2 rate <- 3 Theta <- c(shape, rate) gammaRawMom(1, shape, rate) momIntegrated("gamma", order = 1, param = Theta, about = 0) gammaRawMom(2, shape, rate) momIntegrated("gamma", order = 2, param = Theta, about = 0) gammaRawMom(10, shape, rate) momIntegrated("gamma", order = 10, param = Theta, about = 0) ### Moments of the inverse gamma distribution Theta <- c(-0.5,5,0) gigRawMom(2, Theta) # Inf gigRawMom(-2, Theta) momIntegrated("invgamma", order = -2, param = c(-Theta[1],Theta[2]/2), about = 0) ### An example where the moment is infinite: inverse gamma Theta <- c(-0.5,5,0) gigMom(1, Theta) gigMom(2, Theta)
### Raw moments of the generalized inverse Gaussian distribution Theta <- c(-0.5,5,2.5) gigRawMom(1, Theta) momIntegrated("gig", order = 1, param = Theta, about = 0) gigRawMom(2, Theta) momIntegrated("gig", order = 2, param = Theta, about = 0) gigRawMom(10, Theta) momIntegrated("gig", order = 10, param = Theta, about = 0) gigRawMom(2.5, Theta) ### Moments of the generalized inverse Gaussian distribution Theta <- c(-0.5,5,2.5) (m1 <- gigRawMom(1, Theta)) gigMom(1, Theta) gigMom(2, Theta, m1) (m2 <- momIntegrated("gig", order = 2, param = Theta, about = m1)) gigMom(1, Theta, m1) gigMom(3, Theta, m1) momIntegrated("gig", order = 3, param = Theta, about = m1) ### Raw moments of the gamma distribution shape <- 2 rate <- 3 Theta <- c(shape, rate) gammaRawMom(1, shape, rate) momIntegrated("gamma", order = 1, param = Theta, about = 0) gammaRawMom(2, shape, rate) momIntegrated("gamma", order = 2, param = Theta, about = 0) gammaRawMom(10, shape, rate) momIntegrated("gamma", order = 10, param = Theta, about = 0) ### Moments of the inverse gamma distribution Theta <- c(-0.5,5,0) gigRawMom(2, Theta) # Inf gigRawMom(-2, Theta) momIntegrated("invgamma", order = -2, param = c(-Theta[1],Theta[2]/2), about = 0) ### An example where the moment is infinite: inverse gamma Theta <- c(-0.5,5,0) gigMom(1, Theta) gigMom(2, Theta)
qqgig
produces a generalized inverse Gaussian QQ plot of the
values in y
.
ppgig
produces a generalized inverse Gaussian PP (percent-percent) or
probability plot of the values in y
.
If line = TRUE
, a line with zero intercept and unit slope is
added to the plot.
Graphical parameters may be given as arguments to qqgig
, and
ppgig
.
qqgig(y, Theta, main = "GIG Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppgig(y, Theta, main = "GIG P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
qqgig(y, Theta, main = "GIG Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppgig(y, Theta, main = "GIG P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
y |
The data sample. |
Theta |
Parameters of the generalized inverse Gaussian distribution. |
xlab , ylab , main
|
Plot labels. |
plot.it |
Logical. TRUE denotes the results should be plotted. |
line |
Logical. If TRUE, a line with zero intercept and unit slope is added to the plot. |
... |
Further graphical parameters. |
For qqgig
and ppgig
, a list with components:
x |
The x coordinates of the points that are be plotted. |
y |
The y coordinates of the points that are be plotted. |
Wilk, M. B. and Gnanadesikan, R. (1968) Probability plotting methods for the analysis of data. Biometrika. 55, 1–17.
par(mfrow=c(1,2)) y <- rgig(1000,c(1,2,3)) qqgig(y,c(1,2,3),line=FALSE) abline(0,1,col=2) ppgig(y,c(1,2,3))
par(mfrow=c(1,2)) y <- rgig(1000,c(1,2,3)) qqgig(y,c(1,2,3),line=FALSE) abline(0,1,col=2) ppgig(y,c(1,2,3))
Given the parameter vector Theta of a hyperbolic distribution,
this function calculates the range outside of which the distribution
has negligible probability, or the density function is negligible, to
a specified tolerance. The parameterization used
is the one (see
dhyperb
). To use another parameterization, use
hyperbChangePars
.
hyperbCalcRange(Theta, tol = 10^(-5), density = FALSE)
hyperbCalcRange(Theta, tol = 10^(-5), density = FALSE)
Theta |
Value of parameter vector specifying the hyperbolic distribution. |
tol |
Tolerance. |
density |
Logical. If |
The particular hyperbolic distribution being considered is specified
by the value of the parameter value Theta
.
If density = FALSE
, the function calculates
the effective range of the distribution, which is used in calculating
the distribution function and quantiles, and may be used in determining
the range when plotting the distribution. By effective range is meant that
the probability of an observation being greater than the upper end is
less than the specified tolerance tol
. Likewise for being smaller
than the lower end of the range.
If density = TRUE
, the function gives a range, outside of which
the density is less than the given tolerance. Useful for plotting the
density.
A two-component vector giving the lower and upper ends of the range.
David Scott [email protected], Jennifer Tso, Richard Trendall
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
par(mfrow = c(1,2)) Theta <- c(3,5,1,0) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)) hyperbRange curve(phyperb(x, Theta), hyperbRange[1], hyperbRange[2]) maxDens <- dhyperb(hyperbMode(Theta), Theta) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)*maxDens, density = TRUE) hyperbRange curve(dhyperb(x, Theta), hyperbRange[1], hyperbRange[2])
par(mfrow = c(1,2)) Theta <- c(3,5,1,0) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)) hyperbRange curve(phyperb(x, Theta), hyperbRange[1], hyperbRange[2]) maxDens <- dhyperb(hyperbMode(Theta), Theta) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)*maxDens, density = TRUE) hyperbRange curve(dhyperb(x, Theta), hyperbRange[1], hyperbRange[2])
This function interchanges between the following 4 parameterizations of the hyperbolic distribution:
1.
2.
3.
4.
The first three are given in Barndorff-Nielsen and Blæsild (1983), and the fourth in Prause (1999)
hyperbChangePars(from, to, Theta, noNames = FALSE)
hyperbChangePars(from, to, Theta, noNames = FALSE)
from |
The set of parameters to change from. |
to |
The set of parameters to change to. |
Theta |
"from" parameter vector consisting of 4 numerical elements. |
noNames |
Logical. When |
In the 4 parameterizations, the following must be positive:
1.
2.
3.
4.
Furthermore, note that in the second parameterization
must be greater than the absolute value of
, while in the fourth parameterization,
must be less than one, and the absolute value of
must
be less than
.
A numerical vector of length 4 representing Theta
in the
to
parameterization.
David Scott [email protected], Jennifer Tso, Richard Trendall
Barndorff-Nielsen, O. and Blæsild, P. (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
Theta1 <- c(-2,1,3,0) # Parameterization 1 Theta2 <- hyperbChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 hyperbChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
Theta1 <- c(-2,1,3,0) # Parameterization 1 Theta2 <- hyperbChangePars(1, 2, Theta1) # Convert to parameterization 2 Theta2 # Parameterization 2 hyperbChangePars(2, 1, as.numeric(Theta2)) # Convert back to parameterization 1
Carry out a Crämer-von~Mises test of a hyperbolic distribution where the parameters of the distribution are estimated, or calculate the p-value for such a test.
hyperbCvMTest(x, Theta, conf.level = 0.95, ...) hyperbCvMTestPValue(xi, chi, Wsq, digits = 3) ## S3 method for class 'hyperbCvMTest' print(x, prefix = "\t", ...)
hyperbCvMTest(x, Theta, conf.level = 0.95, ...) hyperbCvMTestPValue(xi, chi, Wsq, digits = 3) ## S3 method for class 'hyperbCvMTest' print(x, prefix = "\t", ...)
x |
A numeric vector of data values for |
Theta |
Parameters of the hyperbolic distribution taking the form
|
conf.level |
Confidence level of the the confidence interval. |
... |
Further arguments to be passed to or from methods. |
xi |
Value of |
chi |
Value of |
Wsq |
Value of the test statistic in the Crämer-von~Mises test of the hyperbolic distribution. |
digits |
Number of decimal places for p-value. |
prefix |
Character(s) to be printed before the description of the test. |
hyperbCvMTest
carries out a Crämer-von~Mises
goodness-of-fit test of the hyperbolic distribution. The parameter
Theta
must be given in the
parameterisation.
hyperbCvMTestPValue
calculates the p-value of the test, and is
not expected to be called by the user. The method used is
interpolation in Table 5 given in Puig & Stephens (2001), which
assumes all the parameters of the distribution are unknown. Since the
table used is limited, large p-values are simply given as
“>~0.25” and very small ones as “<~0.01”. The table is
created as the matrix wsqTable
when the package
HyperbolicDist
is invoked.
print.hyperbCvMTest
prints the output
from the
Crämer-von~Mises goodness-of-fit test for
the hyperbolic distribution in very similar format to that provided by
print.htest
. The only reason for having a special print method
is that p-values can be given as less than some value or greater than
some value, such as “<\ ~0.01”, or “>\ ~0.25”.
hyperbCvMTest
returns a list with class hyperbCvMTest
containing the following components:
statistic |
The value of the test statistic. |
method |
A character string with the value “Crämer-von~Mises test of hyperbolic distribution”. |
data.name |
A character string giving the name(s) of the data. |
parameter |
The value of the parameter Theta. |
p.value |
The p-value of the test. |
warn |
A warning if the parameter values are outside the limits of the table given in Puig & Stephens (2001). |
hyperbCvMTestPValue
returns a list with the elements
p.value
and warn
only.
David Scott, Thomas Tran
Puig, Pedro and Stephens, Michael A. (2001), Goodness-of-fit tests for the hyperbolic distribution. The Canadian Journal of Statistics/La Revue Canadienne de Statistique, 29, 309–320.
Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) fittedTheta <- hyperbFit(dataVector)$Theta hyperbCvMTest(dataVector, fittedTheta) dataVector <- rnorm(1000) fittedTheta <- hyperbFit(dataVector, startValues = "FN")$Theta hyperbCvMTest(dataVector, fittedTheta)
Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) fittedTheta <- hyperbFit(dataVector)$Theta hyperbCvMTest(dataVector, fittedTheta) dataVector <- rnorm(1000) fittedTheta <- hyperbFit(dataVector, startValues = "FN")$Theta hyperbCvMTest(dataVector, fittedTheta)
Fits a hyperbolic distribution to data. Displays the histogram, log-histogram (both with fitted densities), Q-Q plot and P-P plot for the fit which has the maximum likelihood.
hyperbFit(x, freq = NULL, breaks = NULL, ThetaStart = NULL, startMethod = "Nelder-Mead", startValues = "BN", method = "Nelder-Mead", hessian = FALSE, plots = FALSE, printOut = FALSE, controlBFGS = list(maxit=200), controlNM = list(maxit=1000), maxitNLM = 1500, ...) ## S3 method for class 'hyperbFit' print(x, digits = max(3, getOption("digits") - 3), ...) ## S3 method for class 'hyperbFit' plot(x, which = 1:4, plotTitles = paste(c("Histogram of ","Log-Histogram of ", "Q-Q Plot of ","P-P Plot of "), x$obsName, sep = ""), ask = prod(par("mfcol")) < length(which) && dev.interactive(), ...)
hyperbFit(x, freq = NULL, breaks = NULL, ThetaStart = NULL, startMethod = "Nelder-Mead", startValues = "BN", method = "Nelder-Mead", hessian = FALSE, plots = FALSE, printOut = FALSE, controlBFGS = list(maxit=200), controlNM = list(maxit=1000), maxitNLM = 1500, ...) ## S3 method for class 'hyperbFit' print(x, digits = max(3, getOption("digits") - 3), ...) ## S3 method for class 'hyperbFit' plot(x, which = 1:4, plotTitles = paste(c("Histogram of ","Log-Histogram of ", "Q-Q Plot of ","P-P Plot of "), x$obsName, sep = ""), ask = prod(par("mfcol")) < length(which) && dev.interactive(), ...)
x |
Data vector for |
freq |
A vector of weights with length equal to |
breaks |
Breaks for histogram, defaults to those generated by
|
ThetaStart |
A user specified starting parameter vector Theta taking
the form |
startMethod |
Method used by |
startValues |
Code giving the method of determining starting values for finding the maximum likelihood estimate of Theta. |
method |
Different optimisation methods to consider. See Details. |
hessian |
Logical. If |
plots |
Logical. If |
printOut |
Logical. If |
controlBFGS |
A list of control parameters for |
controlNM |
A list of control parameters for |
maxitNLM |
A positive integer specifying the maximum number of
iterations when using the |
digits |
Desired number of digits when the object is printed. |
which |
If a subset of the plots is required, specify a subset of
the numbers |
plotTitles |
Titles to appear above the plots. |
ask |
Logical. If |
... |
Passes arguments to |
startMethod
can be either "BFGS"
or
"Nelder-Mead"
.
startValues
can be one of the following:
"US"
User-supplied.
"BN"
Based on Barndorff-Nielsen (1977).
"FN"
A fitted normal distribution.
"SL"
Based on a fitted skew-Laplace distribution.
"MoM"
Method of moments.
For the details concerning the use of ThetaStart
,
startMethod
, and startValues
, see
hyperbFitStart
.
The three optimisation methods currently available are:
"BFGS"
Uses the quasi-Newton method "BFGS"
as
documented in optim
.
"Nelder-Mead"
Uses an implementation of the Nelder and
Mead method as documented in optim
.
"nlm"
Uses the nlm
function in R.
For details of how to pass control information for optimisation using
optim
and nlm
, see optim
and
nlm.
When method = "nlm"
is used, warnings may be produced. These do
not appear to be a problem.
A list with components:
Theta |
A vector giving the maximum likelihood estimate of
Theta, as |
maxLik |
The value of the maximised log-likelihood. |
hessian |
If |
method |
Optimisation method used. |
conv |
Convergence code. See the relevant documentation (either
|
iter |
Number of iterations of optimisation routine. |
x |
The data used to fit the hyperbolic distribution. |
xName |
A character string with the actual |
ThetaStart |
Starting value of Theta returned by call to
|
svName |
Descriptive name for the method finding start values. |
startValues |
Acronym for the method of finding start values. |
KNu |
Value of the Bessel function in the fitted density. |
breaks |
The cell boundaries found by a call to
|
midpoints |
The cell midpoints found by a call to
|
empDens |
The estimated density found by a call to
|
David Scott [email protected], Ai-Wei Lee, Jennifer Tso, Richard Trendall, Thomas Tran
Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of particle size data. Appl. Statist., 41, 127–146.
optim
, nlm
, par
,
hist
, logHist
, qqhyperb
,
pphyperb
, dskewlap
and
hyperbFitStart
.
Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) ## See how well hyperbFit works hyperbFit(dataVector) hyperbFit(dataVector, plots = TRUE) fit <- hyperbFit(dataVector) par(mfrow = c(1,2)) plot(fit, which = c(1,3)) ## Use nlm instead of default hyperbFit(dataVector, method = "nlm")
Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) ## See how well hyperbFit works hyperbFit(dataVector) hyperbFit(dataVector, plots = TRUE) fit <- hyperbFit(dataVector) par(mfrow = c(1,2)) plot(fit, which = c(1,3)) ## Use nlm instead of default hyperbFit(dataVector, method = "nlm")
Finds starting values for input to a maximum likelihood routine for fitting hyperbolic distribution to data.
hyperbFitStart(x, breaks = NULL, startValues = "BN", ThetaStart = NULL, startMethodSL = "Nelder-Mead", startMethodMoM = "Nelder-Mead", ...) hyperbFitStartMoM(x, startMethodMoM = "Nelder-Mead", ...)
hyperbFitStart(x, breaks = NULL, startValues = "BN", ThetaStart = NULL, startMethodSL = "Nelder-Mead", startMethodMoM = "Nelder-Mead", ...) hyperbFitStartMoM(x, startMethodMoM = "Nelder-Mead", ...)
x |
Data vector. |
breaks |
Breaks for histogram. If missing, defaults to those
generated by |
startValues |
Vector of the different starting values to consider. See Details. |
ThetaStart |
Starting values for Theta if |
startMethodSL |
Method used by call to |
startMethodMoM |
Method used by call to |
... |
Passes arguments to |
Possible values of the argument startValues
are the following:
"US"
User-supplied.
"BN"
Based on Barndorff-Nielsen (1977).
"FN"
A fitted normal distribution.
"SL"
Based on a fitted skew-Laplace distribution.
"MoM"
Method of moments.
If startValues = "US"
then a value must be supplied for
ThetaStart
.
If startValues = "MoM"
, hyperbFitStartMoM
is
called. These starting values are based on Barndorff-Nielsen et
al (1985).
If startValues = "SL"
, or startValues = "MoM"
an initial
optimisation is needed to find the starting values. These
optimisations call optim
.
hyperbFitStart
returns a list with components:
ThetaStart |
A vector with elements |
xName |
A character string with the actual |
breaks |
The cell boundaries found by a call to
|
midpoints |
The cell midpoints found by a call to
|
empDens |
The estimated density found by a call to
|
hyperbFitStartMoM
returns only the method of moments estimates
as a vector with elements pi
, lZeta
(log of zeta),
lDelta
(log of delta), and mu
.
David Scott [email protected], Ai-Wei Lee, Jennifer Tso, Richard Trendall, Thomas Tran
Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.
Barndorff-Nielsen, O., Blæsild, P., Jensen, J., and Sörenson, M. (1985). The fascination of sand. In A celebration of statistics, The ISI Centenary Volume, eds., Atkinson, A. C. and Fienberg, S. E., pp. 57–87. New York: Springer-Verlag.
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of particle size data. Appl. Statist., 41, 127–146.
HyperbolicDistribution
, dskewlap
,
hyperbFit
, hist
, and
optim
.
Theta <- c(2,2,2,2) dataVector <- rhyperb(500,Theta) hyperbFitStart(dataVector,startValues="FN") hyperbFitStartMoM(dataVector) hyperbFitStart(dataVector,startValues="MoM")
Theta <- c(2,2,2,2) dataVector <- rhyperb(500,Theta) hyperbFitStart(dataVector,startValues="FN") hyperbFitStartMoM(dataVector) hyperbFitStart(dataVector,startValues="MoM")
Density function, distribution function, quantiles and
random number generation for the hyperbolic distribution
with parameter vector Theta
. Utility routines are included for
the derivative of the density function and to find suitable break
points for use in determining the distribution function.
dhyperb(x, Theta, KNu = NULL, logPars = FALSE) phyperb(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qhyperb(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rhyperb(n, Theta) ddhyperb(x, Theta, KNu = NULL, ...) hyperbBreaks(Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
dhyperb(x, Theta, KNu = NULL, logPars = FALSE) phyperb(q, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, subdivisions = 100, accuracy = FALSE, ...) qhyperb(p, Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, nInterpol = 100, subdivisions = 100, ...) rhyperb(n, Theta) ddhyperb(x, Theta, KNu = NULL, ...) hyperbBreaks(Theta, small = 10^(-6), tiny = 10^(-10), deriv = 0.3, ...)
x , q
|
Vector of quantiles. |
p |
Vector of probabilities. |
n |
Number of observations to be generated. |
Theta |
Parameter vector taking the form |
KNu |
Sets the value of the Bessel function in the density or derivative of the density. See Details |
.
logPars |
Logical; if |
small |
Size of a small difference between the distribution function and zero or one. See Details. |
tiny |
Size of a tiny difference between the distribution function and zero or one. See Details. |
deriv |
Value between 0 and 1. Determines the point where the derivative becomes substantial, compared to its maximum value. See Details. |
accuracy |
Uses accuracy calculated by |
subdivisions |
The maximum number of subdivisions used to integrate the density returning the distribution function. |
nInterpol |
The number of points used in qhyperb for cubic spline
interpolation (see |
... |
Passes arguments to |
The hyperbolic distribution has density
where is the modified Bessel function of the
third kind with order 1.
A succinct description of the hyperbolic distribution is given in
Barndorff-Nielsen and Blæsild (1983). Three different
possible parameterisations are described in that paper. A fourth
parameterization is given in Prause (1999). All use location and scale
parameters and
. There are two other
parameters in each case.
Use hyperbChangePars
to convert from the
or
parameterisations to the
parameterisation used above.
phyperb
breaks the real line into eight regions in order to
determine the integral of dhyperb
. The break points determining
the regions are found by hyperbBreaks
, based on the values of
small
, tiny
, and deriv
. In the extreme tails of
the distribution where the probability is tiny
according to
hyperbCalcRange
, the probability is taken to be zero. In the
range between where the probability is tiny
and small
according to hyperbCalcRange
, an exponential approximation to
the hyperbolic distribution is used. In the inner part of the
distribution, the range is divided in 4 regions, 2 above the mode, and
2 below. On each side of the mode, the break point which forms the 2
regions is where the derivative of the density function is
deriv
times the maximum value of the derivative on that side of
the mode. In each of the 4 inner regions the numerical integration routine
safeIntegrate
(which is a wrapper for
integrate
) is used to integrate the density dhyperb
.
qhyperb
uses the breakup of the real line into the same 8
regions as phyperb
. For quantiles which fall in the 2 extreme
regions, the quantile is returned as -Inf
or Inf
as
appropriate. In the range between where the probability is tiny
and small
according to hyperbCalcRange
, an exponential
approximation to the hyperbolic distribution is used from which the
quantile may be found in closed form. In the 4 inner regions
splinefun
is used to fit values of the distribution function
generated by phyperb
. The quantiles are then found
using the uniroot
function.
phyperb
and qhyperb
may generally be expected to be
accurate to 5 decimal places.
The hyperbolic distribution is a special case of the generalized
hyperbolic distribution (Barndorff-Nielsen and Blæsild
(1983)). The generalized hyperbolic distribution can be represented as
a particular mixture of the normal distribution where the mixing
distribution is the generalized inverse Gaussian. rhyperb
uses
this representation to generate observations from the hyperbolic
distribution. Generalized inverse Gaussian observations are obtained
via the algorithm of Dagpunar (1989).
dhyperb
gives the density, phyperb
gives the distribution
function, qhyperb
gives the quantile function and rhyperb
generates random variates. An estimate of the accuracy of the
approximation to the distribution function may be found by setting
accuracy = TRUE
in the call to phyperb
which then returns
a list with components value
and error
.
ddhyperb
gives the derivative of dhyperb
.
hyperbBreaks
returns a list with components:
xTiny |
Value such that probability to the left is less than
|
xSmall |
Value such that probability to the left is less than
|
lowBreak |
Point to the left of the mode such that the
derivative of the density is |
highBreak |
Point to the right of the mode such that the
derivative of the density is |
xLarge |
Value such that probability to the right is less than
|
xHuge |
Value such that probability to the right is less than
|
modeDist |
The mode of the given hyperbolic distribution. |
David Scott [email protected], Ai-Wei Lee, Jennifer Tso, Richard Trendall
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Dagpunar, J.S. (1989). An easily implemented generalized inverse Gaussian generator Commun. Statist. -Simula., 18, 703–710.
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
safeIntegrate
, integrate
for its
shortfalls, splinefun
, uniroot
and
hyperbChangePars
for changing parameters to the
parameterisation,
dghyp
for
the generalized hyperbolic distribution.
Theta <- c(2,1,1,0) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Density of the\n Hyperbolic Distribution") curve(phyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Distribution Function of the\n Hyperbolic Distribution") dataVector <- rhyperb(500, Theta) curve(dhyperb(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram\n of the Hyperbolic Distribution") logHist(dataVector, main = "Log-Density and Log-Histogram\n of the Hyperbolic Distribution") curve(log(dhyperb(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Density of the\n Hyperbolic Distribution") curve(ddhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Derivative of the Density\n of the Hyperbolic Distribution") par(mfrow = c(1,1)) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-6)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) bks <- hyperbBreaks(Theta) abline(v = bks)
Theta <- c(2,1,1,0) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-3)) par(mfrow = c(1,2)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Density of the\n Hyperbolic Distribution") curve(phyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Distribution Function of the\n Hyperbolic Distribution") dataVector <- rhyperb(500, Theta) curve(dhyperb(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram\n of the Hyperbolic Distribution") logHist(dataVector, main = "Log-Density and Log-Histogram\n of the Hyperbolic Distribution") curve(log(dhyperb(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500) par(mfrow = c(2,1)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Density of the\n Hyperbolic Distribution") curve(ddhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) title("Derivative of the Density\n of the Hyperbolic Distribution") par(mfrow = c(1,1)) hyperbRange <- hyperbCalcRange(Theta, tol = 10^(-6)) curve(dhyperb(x, Theta), from = hyperbRange[1], to = hyperbRange[2], n = 1000) bks <- hyperbBreaks(Theta) abline(v = bks)
This package provides a collection of functions for working with the hyperbolic and related distributions.
For the hyperbolic distribution functions are provided for the density
function, distribution function, quantiles, random number generation and
fitting the hyperbolic distribution to data (hyperbFit
). The function
hyperbChangePars
will interchange parameter values between
different parameterisations. The mean, variance, skewness, kurtosis and
mode of a given hyperbolic distribution are given by hyperbMean
,
hyperbVar
, hyperbSkew
, hyperbKurt
, and
hyperbMode
respectively. For assessing the fit of the hyperbolic
distribution to a set of data, the log-histogram is useful. See
logHist
. Q-Q and P-P plots are also provided for assessing
the fit of a hyperbolic distribution. A Crämer-von~Mises
test of the goodness of fit of data to a hyperbolic distribution is given by
hyperbCvMTest
. S3 print
, plot
and summary
methods are provided for the output of hyperbFit
.
For the generalized hyperbolic distribution functions are provided for
the density function, distribution function, quantiles, and for random
number generation. The function ghypChangePars
will interchange
parameter values between different parameterisations. The mean, variance, and
mode of a given generalized hyperbolic distribution are given by
ghypMean
, ghypVar
, ghypSkew
, ghypKurt
, and
ghypMode
respectively. Q-Q and P-P plots are also provided for
assessing the fit of a generalized hyperbolic distribution.
For the generalized inverse Gaussian distribution functions are provided for
the density function, distribution function, quantiles, and for random
number generation. The function gigChangePars
will interchange
parameter values between different parameterisations. The mean,
variance, skewness, kurtosis and mode of a given generalized inverse
Gaussian distribution are given by gigMean
, gigVar
,
gigSkew
, gigKurt
, and gigMode
respectively. Q-Q and
P-P plots are also provided for assessing the fit of a generalized
inverse Gaussian distribution.
For the skew-Laplace distribution functions are provided for the density function, distribution function, quantiles, and for random number generation. Q-Q and P-P plots are also provided for assessing the fit of a skew-Laplace distribution.
A number of students have worked on the package: Ai-Wei Lee, Jennifer Tso, Richard Trendall, and Thomas Tran.
Thanks to Ross Ihaka and Paul Murrell for their willingness to answer my questions, and to all the core group for the development of R.
This library and its documentation are usable under the terms of the "GNU General Public License", a copy of which is distributed with the package.
David Scott [email protected]
Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of particle size data. Appl. Statist., 41, 127–146.
Jörgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
qqhyperb
produces a hyperbolic Q-Q plot of the values in
y
.
pphyperb
produces a hyperbolic P-P (percent-percent) or
probability plot of the values in y
.
Graphical parameters may be given as arguments to qqhyperb
,
and pphyperb
.
qqhyperb(y, Theta, main = "Hyperbolic Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) pphyperb(y, Theta, main = "Hyperbolic P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
qqhyperb(y, Theta, main = "Hyperbolic Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) pphyperb(y, Theta, main = "Hyperbolic P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
y |
The data sample. |
Theta |
Parameters of the hyperbolic distribution. |
xlab , ylab , main
|
Plot labels. |
plot.it |
Logical. Should the result be plotted? |
line |
Add line through origin with unit slope. |
... |
Further graphical parameters. |
For qqhyperb
and pphyperb
, a list with components:
x |
The x coordinates of the points that are to be plotted. |
y |
The y coordinates of the points that are to be plotted. |
Wilk, M. B. and Gnanadesikan, R. (1968) Probability plotting methods for the analysis of data. Biometrika. 55, 1–17.
par(mfrow = c(1,2)) y <- rhyperb(200, c(2,2,2,2)) qqhyperb(y, c(2,2,2,2),line = FALSE) abline(0, 1, col = 2) pphyperb(y, c(2,2,2,2))
par(mfrow = c(1,2)) y <- rhyperb(200, c(2,2,2,2)) qqhyperb(y, c(2,2,2,2),line = FALSE) abline(0, 1, col = 2) pphyperb(y, c(2,2,2,2))
This gives Table 5 of Puig & Stephens (2001) which is used for testing
the goodness-of-fit of the hyperbolic distribution using the
Crämer-von~Mises test. It is for internal use by
hyperbCvMTest
and hyperbCvMTestPValue
only and is not
intended to be accessed by the user. It is loaded automatically when
the package HyperbolicDist
is invoked.
The hyperbWSqTable
matrix has 55 rows and 5 columns, giving
percentage points of for different values of
and
(the rows), and of
(the columns).
Puig, Pedro and Stephens, Michael A. (2001), Goodness-of-fit tests for the hyperbolic distribution. The Canadian Journal of Statistics/La Revue Canadienne de Statistique, 29, 309–320.
Checks whether an object is numeric and if so, are all the elements whole numbers, to a given tolerance.
is.wholenumber(x, tolerance = .Machine$double.eps^0.5)
is.wholenumber(x, tolerance = .Machine$double.eps^0.5)
x |
The object to be tested. |
tolerance |
Numeric |
The object x
is first tested to see if it is numeric. If not
the function returns 'FALSE'
. Then if all the elements of
x
are whole numbers to within the tolerance given by
tolerance
the function returns 'TRUE'
. If not it returns
'FALSE'
.
Either 'TRUE'
or 'FALSE'
depending on the result of the
test.
David Scott [email protected].
Based on a post by Tony Plate <[email protected]> on R-help.
is.wholenumber(-3:5) # TRUE is.wholenumber(c(0,0.1,1.3,5)) # FALSE is.wholenumber(-3:5 + .Machine$double.eps) # TRUE is.wholenumber(-3:5 + .Machine$double.eps^0.5) # FALSE is.wholenumber(c(2L,3L)) # TRUE is.wholenumber(c("2L","3L")) # FALSE is.wholenumber(0i ^ (-3:3)) # FALSE is.wholenumber(matrix(1:6, nrow = 3)) # TRUE is.wholenumber(list(-1:3,2:6)) # FALSE is.numeric(list(-1:3,2:6)) # FALSE is.wholenumber(unlist(list(-1:3,2:6))) # TRUE
is.wholenumber(-3:5) # TRUE is.wholenumber(c(0,0.1,1.3,5)) # FALSE is.wholenumber(-3:5 + .Machine$double.eps) # TRUE is.wholenumber(-3:5 + .Machine$double.eps^0.5) # FALSE is.wholenumber(c(2L,3L)) # TRUE is.wholenumber(c("2L","3L")) # FALSE is.wholenumber(0i ^ (-3:3)) # FALSE is.wholenumber(matrix(1:6, nrow = 3)) # TRUE is.wholenumber(list(-1:3,2:6)) # FALSE is.numeric(list(-1:3,2:6)) # FALSE is.wholenumber(unlist(list(-1:3,2:6))) # TRUE
Plots a log-histogram, as in for example Feiller, Flenley and Olbricht (1992).
The intended use of the log-histogram is to examine the fit of a particular density to a set of data, as an alternative to a histogram with a density curve. For this reason, only the log-density histogram is implemented, and it is not possible to obtain a log-frequency histogram.
The log-histogram can be plotted with histogram-like dashed vertical bars, or as points marking the tops of the log-histogram bars, or with both bars and points.
logHist(x, breaks = "Sturges", include.lowest = TRUE, right = TRUE, main = paste("Log-Histogram of", xName), xlim = range(breaks), ylim = NULL, xlab = xName, ylab = "Log-density", nclass = NULL, htype = "b", ...)
logHist(x, breaks = "Sturges", include.lowest = TRUE, right = TRUE, main = paste("Log-Histogram of", xName), xlim = range(breaks), ylim = NULL, xlab = xName, ylab = "Log-density", nclass = NULL, htype = "b", ...)
x |
A vector of values for which the log-histogram is desired. |
breaks |
One of:
In the last three cases the number is a suggestion only. |
include.lowest |
Logical. If |
right |
Logical. If |
main , xlab , ylab
|
These arguments to |
xlim |
Sensible default for the range of x values. |
ylim |
Calculated by |
nclass |
Numeric (integer). For compatibility with |
htype |
Type of histogram. Possible types are:
|
... |
Further graphical parameters for calls
to |
Uses hist.default
to determine the cells or classes and
calculate counts.
To calculate ylim
the following procedure is used. The upper
end of the range is given by the maximum value of the log-density,
plus 25% of the absolute value of the maximum. The lower end of the
range is given by the smallest (finite) value of the log-density, less
25% of the difference between the largest and smallest (finite) values
of the log-density.
A log-histogram in the form used by Feiller, Flenley and Olbricht (1992) is plotted. See also Barndorff-Nielsen (1977) for use of log-histograms.
Returns a list with components:
breaks |
The |
counts |
|
logDensity |
Log of If |
mids |
The |
xName |
A character string with the actual |
heights |
The location of the tops of the vertical segments used in drawing the log-histogram. |
ylim |
The value of |
David Scott [email protected], Richard Trendall, Thomas Tran
Barndorff-Nielsen, O. (1977) Exponentially decreasing distributions for the logarithm of particle size, Proc. Roy. Soc. Lond., A353, 401–419.
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of particle size data. Appl. Statist., 41, 127–146.
data(SandP500) ### Consider proportional changes in the index change <- SandP500[-length(SandP500)]/SandP500[-1] hist(change) logHist(change) ### Show points only logHist(change, htype = "p", pch = 20, cex = 0.5) ### Fit the hyperbolic distribution to the changes hyperbFit(change)
data(SandP500) ### Consider proportional changes in the index change <- SandP500[-length(SandP500)]/SandP500[-1] hist(change) logHist(change) ### Show points only logHist(change, htype = "p", pch = 20, cex = 0.5) ### Fit the hyperbolic distribution to the changes hyperbFit(change)
Size of gravels collected from a sandbar in the Mamquam River, British Columbia, Canada. Summary data, giving the frequency of observations in 16 different size classes.
data(mamquam)
data(mamquam)
The mamquam
data frame has 16 rows and 2 columns.
[, 1] | midpoints | midpoints of intervals (psi units) |
[, 2] | counts | number of observations in interval |
Gravel sizes are determined by passing clasts through templates of particular sizes. This gives a range in which the size of each clast lies. Sizes (in mm) are then converted into psi units by taking the base 2 logarithm of the size. The midpoints specified are the midpoints of the psi unit ranges, and counts gives the number of observations in each size range. The classes are of length 0.5 psi units. There are 3574 observations.
Rice, Stephen and Church, Michael (1996) Sampling surficial gravels: the precision of size distribution percentile estimates. J. of Sedimentary Research, 66, 654–665.
data(mamquam) str(mamquam) attach(mamquam) ### Construct data from frequency summary, taking all observations ### at midpoints of intervals psi <- rep(midpoints, counts) barplot(table(psi)) ### Fit the hyperbolic distribution hyperbFit(psi) ### Actually hyperbFit can deal with frequency data hyperbFit(midpoints, freq=counts)
data(mamquam) str(mamquam) attach(mamquam) ### Construct data from frequency summary, taking all observations ### at midpoints of intervals psi <- rep(midpoints, counts) barplot(table(psi)) ### Fit the hyperbolic distribution hyperbFit(psi) ### Actually hyperbFit can deal with frequency data hyperbFit(midpoints, freq=counts)
Using the moments up to a given order about one location, this function either returns the moments up to that given order about a new location as a vector or it returns a moment of a specific order defined by users (order <= maximum order of the given moments) about a new location as a single number. A generalization of using raw moments to obtain a central moment or using central moments to obtain a raw moment.
momChangeAbout(order = "all", oldMom, oldAbout, newAbout)
momChangeAbout(order = "all", oldMom, oldAbout, newAbout)
order |
One of:
|
oldMom |
Numeric. Moments of orders 1, 2, ..., about the point
|
oldAbout |
Numeric. The point about which the moments |
newAbout |
Numeric. The point about which the desired moment or moments are to be obtained. |
Suppose denotes the
-th moment of a random
variable
about a point
, and
denotes the
-th moment about
. Then
may be determined from the moments
according to the formula
This is the formula implemented by the function
momChangeAbout
. It is a generalization of the well-known
formulae used to change raw moments to central moments or to change
central moments to raw moments. See for example Kendall and Stuart
(1989), Chapter 3.
The moment of order order
about the location newAbout
when
order
is specified.
The vector of moments about the location newAbout
from first
order up to the maximum order of the oldMom
when order
takes the value "all"
or is not specified.
David Scott [email protected], Christine Yang Dong [email protected]
Kendall, M. G. and Stuart, A. (1969). The Advanced Theory of Statistics, Volume 1, 3rd Edition. London: Charles Griffin & Company.
### Gamma distribution k <- 4 shape <- 2 old <- 0 new <- 1 sampSize <- 1000000 ### Calculate 1st to 4th raw moments m <- numeric(k) for (i in 1:k){ m[i] <- gamma(shape + i)/gamma(shape) } m ### Calculate 4th moment about new momChangeAbout(k, m, old, new) ### Calculate 3rd about new momChangeAbout(3, m, old, new) ### Calculate 1st to 4th moments about new momChangeAbout(oldMom = m, oldAbout = old, newAbout = new) momChangeAbout(order = "all", m, old, new) ### Approximate kth moment about new using sampling x <- rgamma(sampSize, shape) mean((x - new)^k)
### Gamma distribution k <- 4 shape <- 2 old <- 0 new <- 1 sampSize <- 1000000 ### Calculate 1st to 4th raw moments m <- numeric(k) for (i in 1:k){ m[i] <- gamma(shape + i)/gamma(shape) } m ### Calculate 4th moment about new momChangeAbout(k, m, old, new) ### Calculate 3rd about new momChangeAbout(3, m, old, new) ### Calculate 1st to 4th moments about new momChangeAbout(oldMom = m, oldAbout = old, newAbout = new) momChangeAbout(order = "all", m, old, new) ### Approximate kth moment about new using sampling x <- rgamma(sampSize, shape) mean((x - new)^k)
Calculates moments and absolute moments about a given location for the generalized hyperbolic and related distributions.
momIntegrated(densFn, order, param = NULL, about = 0, absolute = FALSE)
momIntegrated(densFn, order, param = NULL, about = 0, absolute = FALSE)
densFn |
Character. The name of the density function whose moments are to be calculated. See Details. |
order |
Numeric. The order of the moment or absolute moment to be calculated. |
param |
Numeric. A vector giving the parameter values for the
distribution specified by |
about |
Numeric. The point about which the moment is to be calculated. |
absolute |
Logical. Whether absolute moments or ordinary moments
are to be calculated. Default is |
Denote the density function by . Then if
order
and
about
,
momIntegrated
calculates
when absolute = FALSE
and
when absolute = TRUE
.
Only certain density functions are permitted.
When densFn="ghyp"
or "generalized hyperbolic"
the
density used is dghyp
. The default value for param
is
c(1,1,0,1,0)
.
When densFn="hyperb"
or "hyperbolic"
the density used is
dhyperb
. The default value for param
is
c(0,1,1,0)
.
When densFn="gig"
or "generalized inverse gaussian"
the
density used is dgig
. The default value for param
is
c(1,1,1)
.
When densFn="gamma"
the density used is dgamma
. The
default value for param
is c(1,1)
.
When densFn="invgamma"
or "inverse gamma"
the
density used is the density of the inverse gamma distribution given by
for ,
and
. The parameter vector
param = c(shape,rate)
where shape
and
rate
. The default value for
param
is c(-1,1)
.
The value of the integral as specified in Details.
David Scott [email protected], Christine Yang Dong [email protected]
### Calculate the mean of a generalized hyperbolic distribution ### Compare the use of integration and the formula for the mean m1 <- momIntegrated("ghyp", param = c(1/2,3,1,1,0), order = 1, about = 0) m1 ghypMean(c(1/2,3,1,1,0)) ### The first moment about the mean should be zero momIntegrated("ghyp", order = 1, param = c(1/2,3,1,1,0), about = m1) ### The variance can be calculated from the raw moments m2 <- momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = 0) m2 m2 - m1^2 ### Compare with direct calculation using integration momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = m1) momIntegrated("generalized hyperbolic", param = c(1/2,3,1,1,0), order = 2, about = m1) ### Compare with use of the formula for the variance ghypVar(c(1/2,3,1,1,0))
### Calculate the mean of a generalized hyperbolic distribution ### Compare the use of integration and the formula for the mean m1 <- momIntegrated("ghyp", param = c(1/2,3,1,1,0), order = 1, about = 0) m1 ghypMean(c(1/2,3,1,1,0)) ### The first moment about the mean should be zero momIntegrated("ghyp", order = 1, param = c(1/2,3,1,1,0), about = m1) ### The variance can be calculated from the raw moments m2 <- momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = 0) m2 m2 - m1^2 ### Compare with direct calculation using integration momIntegrated("ghyp", order = 2, param = c(1/2,3,1,1,0), about = m1) momIntegrated("generalized hyperbolic", param = c(1/2,3,1,1,0), order = 2, about = m1) ### Compare with use of the formula for the variance ghypVar(c(1/2,3,1,1,0))
This function computes all of the moments coefficients by recursion based on Scott, Würtz and Tran (2008). See Details for the formula.
momRecursion(order = 12, printMatrix = FALSE)
momRecursion(order = 12, printMatrix = FALSE)
order |
Numeric. The order of the moment coefficients to be calculated. Not permitted to be a vector. Must be a positive whole number except for moments about zero. |
printMatrix |
Logical. Should the coefficients matrix be printed? |
The moment coefficients recursively as and
with
for
or
where
=
order
, is equal to the integers from
to
.
This formula is given in Scott, Würtz and Tran (2008, working paper).
The function also calculates M which is equal to .
It is a common term which will appear in the formulae
for calculating moments of generalized hyperbolic and related distributions.
a |
The non-zero moment coefficients for the specified order. |
l |
Integers from ( |
M |
The common term used when computing mu moments for generalized
hyperbolic and related distributions, M = |
lmin |
The minimum of |
David Scott [email protected], Christine Yang Dong [email protected]
Scott, D. J., Würtz, D. and Tran, T. T. (2008) Moments of the Generalized Hyperbolic Distribution. Preprint.
momRecursion(order = 12) #print out the matrix momRecursion(order = 12, "true")
momRecursion(order = 12) #print out the matrix momRecursion(order = 12, "true")
This data set gives the resistance in ohms of 500 nominally one-half-ohm resistors, presented in Hahn and Shapiro (1967). Summary data giving the frequency of observations in 28 intervals.
data(resistors)
data(resistors)
The resistors
data frame has 28 rows and 2 columns.
[, 1] | midpoints | midpoints of intervals (ohm) |
[, 2] | counts | number of observations in interval |
Hahn, Gerald J. and Shapiro, Samuel S. (1967) Statistical Models in Engineering. New York: Wiley, page 207.
Chen, Hanfeng, and Kamburowska, Grazyna (2001) Fitting data to the Johnson system. J. Statist. Comput. Simul., 70, 21–32.
data(resistors) str(resistors) attach(resistors) ### Construct data from frequency summary, taking all observations ### at midpoints of intervals resistances <- rep(midpoints,counts) hist(resistances) logHist(resistances) ## Fit the hyperbolic distribution hyperbFit(resistances) ## Actually fit.hyperb can deal with frequency data hyperbFit(midpoints, freq=counts)
data(resistors) str(resistors) attach(resistors) ### Construct data from frequency summary, taking all observations ### at midpoints of intervals resistances <- rep(midpoints,counts) hist(resistances) logHist(resistances) ## Fit the hyperbolic distribution hyperbFit(resistances) ## Actually fit.hyperb can deal with frequency data hyperbFit(midpoints, freq=counts)
Adaptive quadrature of functions of one variable over a finite or infinite interval.
safeIntegrate(f, lower, upper, subdivisions=100, rel.tol = .Machine$double.eps^0.25, abs.tol = rel.tol, stop.on.error = TRUE, keep.xy = FALSE, aux = NULL, ...)
safeIntegrate(f, lower, upper, subdivisions=100, rel.tol = .Machine$double.eps^0.25, abs.tol = rel.tol, stop.on.error = TRUE, keep.xy = FALSE, aux = NULL, ...)
f |
An R function taking a numeric first argument and returning a numeric vector of the same length. Returning a non-finite element will generate an error. |
lower , upper
|
The limits of integration. Can be infinite. |
subdivisions |
The maximum number of subintervals. |
rel.tol |
Relative accuracy requested. |
abs.tol |
Absolute accuracy requested. |
stop.on.error |
Logical. If true (the default) an error stops the
function. If false some errors will give a result with a warning in
the |
keep.xy |
Unused. For compatibility with S. |
aux |
Unused. For compatibility with S. |
... |
Additional arguments to be passed to |
This function is just a wrapper around
integrate
to check for equality of
upper
and lower
. A check is made using
all.equal
. When numerical equality is
detected, if lower
(and hence upper
) is infinite, the
value of the integral and the absolute error are both set to 0. When
lower
is finite, the value of the integral is set to 0, and the
absolute error to the average of the function values at upper
and
lower
times the difference between upper
and lower
.
When upper
and lower
are determined to be different, the
result is exactly as given by integrate
.
A list of class "integrate"
with components:
value |
The final estimate of the integral. |
abs.error |
Estimate of the modulus of the absolute error. |
subdivisions |
The number of subintervals produced in the subdivision process. |
message |
|
call |
The matched call. |
The function integrate
and
all.equal
.
integrate(dnorm, -1.96, 1.96) safeIntegrate(dnorm, -1.96, 1.96) # Same as for integrate() integrate(dnorm, -Inf, Inf) safeIntegrate(dnorm, -Inf, Inf) # Same as for integrate() integrate(dnorm, 1.96, 1.96) # OK here but can give an error safeIntegrate(dnorm, 1.96, 1.96) integrate(dnorm, -Inf, -Inf) safeIntegrate(dnorm, -Inf, -Inf) # Avoids nonsense answer integrate(dnorm, Inf, Inf) safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer
integrate(dnorm, -1.96, 1.96) safeIntegrate(dnorm, -1.96, 1.96) # Same as for integrate() integrate(dnorm, -Inf, Inf) safeIntegrate(dnorm, -Inf, Inf) # Same as for integrate() integrate(dnorm, 1.96, 1.96) # OK here but can give an error safeIntegrate(dnorm, 1.96, 1.96) integrate(dnorm, -Inf, -Inf) safeIntegrate(dnorm, -Inf, -Inf) # Avoids nonsense answer integrate(dnorm, Inf, Inf) safeIntegrate(dnorm, Inf, Inf) # Avoids nonsense answer
Computes the sample skewness and sample kurtosis.
skewness(x, na.rm = FALSE) kurtosis(x, na.rm = FALSE)
skewness(x, na.rm = FALSE) kurtosis(x, na.rm = FALSE)
x |
A numeric vector containing the values whose skewness or kurtosis is to be computed. |
na.rm |
A logical value indicating whether |
If , then the skewness of
is defined as
If , then the kurtosis of
is defined as
The skewness or kurtosis of x
.
These functions and the description of them are taken from the
package e1071
. They are included to avoid having to require an
additional package.
Evgenia Dimitriadou, Kurt Hornik, Friedrich Leisch, David Meyer, and Andreas Weingessel
x <- rnorm(100) skewness(x) kurtosis(x)
x <- rnorm(100) skewness(x) kurtosis(x)
This data set gives the value of Standard and Poor's most notable stock market price index (the S&P 500) at year end, from 1800 to 2001.
data(SandP500)
data(SandP500)
A vector of 202 observations.
At the time of downloading, http://www.globalfindata.com
which no longer exists. Now at https://globalfinancialdata.com
.
Brown, Barry W., Spears, Floyd M. and Levy, Lawrence B. (2002) The log F: a distribution for all seasons. Computational Statistics, 17, 47–58.
data(SandP500) ### Consider proportional changes in the index change<-SandP500[-length(SandP500)]/SandP500[-1] hist(change) ### Fit hyperbolic distribution to changes hyperbFit(change)
data(SandP500) ### Consider proportional changes in the index change<-SandP500[-length(SandP500)]/SandP500[-1] hist(change) ### Fit hyperbolic distribution to changes hyperbFit(change)
Density function, distribution function, quantiles and random number generation for the skew-Laplace distribution.
dskewlap(x, Theta, logPars = FALSE) pskewlap(q, Theta) qskewlap(p, Theta) rskewlap(n, Theta)
dskewlap(x, Theta, logPars = FALSE) pskewlap(q, Theta) qskewlap(p, Theta) rskewlap(n, Theta)
x , q
|
Vector of quantiles. |
p |
Vector of probabilities. |
n |
Number of observations to be generated. |
Theta |
Vector of parameters of the skew-Laplace distribution:
|
.
logPars |
Logical. If |
The central skew-Laplace has mode zero, and is a mixture of a (negative)
exponential distribution with mean , and the negative of an
exponential distribution with mean
. The weights of
the positive and negative components are proportional to their means.
The general skew-Laplace distribution is a shifted central skew-Laplace
distribution, where the mode is given by .
The density is given by:
for , and
for
dskewlap
gives the density, pskewlap
gives the distribution
function, qskewlap
gives the quantile function and rskewlap
generates random variates. The distribution function is obtained by
elementary integration of the density function. Random variates are
generated from exponential observations using the characterization of
the skew-Laplace as a mixture of exponential observations.
David Scott [email protected], Ai-Wei Lee, Richard Trendall
Fieller, N. J., Flenley, E. C. and Olbricht, W. (1992) Statistics of particle size data. Appl. Statist., 41, 127–146.
Theta <- c(1,2,1) par(mfrow = c(1,2)) curve(dskewlap(x, Theta), from = -5, to = 8, n = 1000) title("Density of the\n Skew-Laplace Distribution") curve(pskewlap(x, Theta), from = -5, to = 8, n = 1000) title("Distribution Function of the\n Skew-Laplace Distribution") dataVector <- rskewlap(500, Theta) curve(dskewlap(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram\n of the Skew-Laplace Distribution") logHist(dataVector, main = "Log-Density and Log-Histogram\n of the Skew-Laplace Distribution") curve(log(dskewlap(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500)
Theta <- c(1,2,1) par(mfrow = c(1,2)) curve(dskewlap(x, Theta), from = -5, to = 8, n = 1000) title("Density of the\n Skew-Laplace Distribution") curve(pskewlap(x, Theta), from = -5, to = 8, n = 1000) title("Distribution Function of the\n Skew-Laplace Distribution") dataVector <- rskewlap(500, Theta) curve(dskewlap(x, Theta), range(dataVector)[1], range(dataVector)[2], n = 500) hist(dataVector, freq = FALSE, add =TRUE) title("Density and Histogram\n of the Skew-Laplace Distribution") logHist(dataVector, main = "Log-Density and Log-Histogram\n of the Skew-Laplace Distribution") curve(log(dskewlap(x, Theta)), add = TRUE, range(dataVector)[1], range(dataVector)[2], n = 500)
qqskewlap
produces a skew-Laplace QQ plot of the
values in y
.
ppskewlap
produces a skew-Laplace PP (percent-percent) or
probability plot of the values in y
.
If line = TRUE
, a line with zero intercept and unit slope is
added to the plot.
Graphical parameters may be given as arguments to qqskewlap
, and
ppskewlap
.
qqskewlap(y, Theta, main = "Skew-Laplace Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppskewlap(y, Theta, main = "Skew-Laplace P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
qqskewlap(y, Theta, main = "Skew-Laplace Q-Q Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppskewlap(y, Theta, main = "Skew-Laplace P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
y |
The data sample. |
Theta |
Parameters of the skew-Laplace distribution. |
xlab , ylab , main
|
Plot labels. |
plot.it |
Logical. TRUE denotes the results should be plotted. |
line |
Logical. If TRUE, a line with zero intercept and unit slope is added to the plot. |
... |
Further graphical parameters. |
For qqskewlap
and ppskewlap
, a list with components:
x |
The x coordinates of the points that are be plotted. |
y |
The y coordinates of the points that are be plotted. |
Wilk, M. B. and Gnanadesikan, R. (1968) Probability plotting methods for the analysis of data. Biometrika. 55, 1–17.
par(mfrow=c(1,2)) y <- rskewlap(1000,c(0.5,1,2)) qqskewlap(y,c(0.5,1,2),line=FALSE) abline(0,1,col=2) ppskewlap(y,c(0.5,1,2))
par(mfrow=c(1,2)) y <- rskewlap(1000,c(0.5,1,2)) qqskewlap(y,c(0.5,1,2),line=FALSE) abline(0,1,col=2) ppskewlap(y,c(0.5,1,2))
Functions to calculate the mean, variance, skewness, kurtosis and mode of a specific generalized hyperbolic distribution.
ghypMean(Theta) ghypVar(Theta) ghypSkew(Theta) ghypKurt(Theta) ghypMode(Theta)
ghypMean(Theta) ghypVar(Theta) ghypSkew(Theta) ghypKurt(Theta) ghypMode(Theta)
Theta |
Parameter vector of the generalized hyperbolic distribution. |
ghypMean
gives the mean of the generalized hyperbolic distribution,
ghypVar
the variance, ghypSkew
the skewness,
ghypKurt
the kurtosis, and ghypMode
the mode. The
formulae used for the mean is given in Prause (1999). The variance,
skewness and kurtosis are obtained using the recursive formula
implemented in ghypMom
which can calculate moments of
all orders about any point.
The mode is found by a numerical optimisation using
optim
. For the special case of the hyperbolic
distribution a formula for the mode is available, see
hyperbMode
.
The parameterization of the generalized hyperbolic distribution used
for these functions is the one. See
ghypChangePars
to transfer between parameterizations.
David Scott [email protected], Thomas Tran
Prause, K. (1999) The generalized hyperbolic models: Estimation, financial derivatives and risk measurement. PhD Thesis, Mathematics Faculty, University of Freiburg.
dghyp
, ghypChangePars
,
besselK
, RLambda
.
Theta <- c(2,2,1,2,2) ghypMean(Theta) ghypVar(Theta) ghypSkew(Theta) ghypKurt(Theta) ghypMode(Theta) maxDens <- dghyp(ghypMode(Theta), Theta) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)*maxDens) curve(dghyp(x, Theta), ghypRange[1], ghypRange[2]) abline(v = ghypMode(Theta), col = "blue") abline(v = ghypMean(Theta), col = "red")
Theta <- c(2,2,1,2,2) ghypMean(Theta) ghypVar(Theta) ghypSkew(Theta) ghypKurt(Theta) ghypMode(Theta) maxDens <- dghyp(ghypMode(Theta), Theta) ghypRange <- ghypCalcRange(Theta, tol = 10^(-3)*maxDens) curve(dghyp(x, Theta), ghypRange[1], ghypRange[2]) abline(v = ghypMode(Theta), col = "blue") abline(v = ghypMean(Theta), col = "red")
Functions to calculate the mean, variance, skewness, kurtosis and mode of a specific generalized inverse Gaussian distribution.
gigMean(Theta) gigVar(Theta) gigSkew(Theta) gigKurt(Theta) gigMode(Theta)
gigMean(Theta) gigVar(Theta) gigSkew(Theta) gigKurt(Theta) gigMode(Theta)
Theta |
Parameter vector of the generalized inverse Gaussian distribution. |
gigMean
gives the mean of the generalized inverse Gaussian
distribution, gigVar
the variance, gigSkew
the skewness,
gigKurt
the kurtosis, and gigMode
the mode. The formulae
used are as given in Jorgensen (1982),
pp. 13–17. Note that the kurtosis is the standardised fourth cumulant
or what is sometimes called the kurtosis excess. (See
http://mathworld.wolfram.com/Kurtosis.html for a discussion.)
The parameterization used for the generalized inverse Gaussian
distribution is the one (see
dgig
). To use another parameterization, use
gigChangePars
.
David Scott [email protected]
Jorgensen, B. (1982). Statistical Properties of the Generalized Inverse Gaussian Distribution. Lecture Notes in Statistics, Vol. 9, Springer-Verlag, New York.
Theta <- c(-0.5,5,2.5) gigMean(Theta) gigVar(Theta) gigSkew(Theta) gigKurt(Theta) gigMode(Theta)
Theta <- c(-0.5,5,2.5) gigMean(Theta) gigVar(Theta) gigSkew(Theta) gigKurt(Theta) gigMode(Theta)
Functions to calculate the mean, variance, skewness, kurtosis and mode of a specific hyperbolic distribution.
hyperbMean(Theta) hyperbVar(Theta) hyperbSkew(Theta) hyperbKurt(Theta) hyperbMode(Theta)
hyperbMean(Theta) hyperbVar(Theta) hyperbSkew(Theta) hyperbKurt(Theta) hyperbMode(Theta)
Theta |
Parameter vector of the hyperbolic distribution. |
The formulae used for the mean, variance and mode are as given in Barndorff-Nielsen and Blæsild (1983), p. 702. The formulae used for the skewness and kurtosis are those of Barndorff-Nielsen and Blæsild (1981), Appendix 2.
Note that the variance, skewness and kurtosis can be obtained from the
functions for the generalized hyperbolic distribution as special
cases. Likewise other moments can be obtained from the function
ghypMom
which implements a recursive method to moments
of any desired order. Note that functions for the generalized
hyperbolic distribution use a different parameterization, so care is
required.
hyperbMean
gives the mean of the hyperbolic distribution,
hyperbVar
the variance, hyperbSkew
the skewness,
hyperbKurt
the kurtosis and hyperbMode
the mode.
Note that the kurtosis is the standardised fourth cumulant or what is sometimes called the kurtosis excess. (See http://mathworld.wolfram.com/Kurtosis.html for a discussion.)
The parameterization of the hyperbolic distribution used for this
and other components of the HyperbolicDist
package is the
one. See
hyperbChangePars
to transfer between parameterizations.
David Scott [email protected], Richard Trendall, Thomas Tran
Barndorff-Nielsen, O. and Blæsild, P (1981). Hyperbolic distributions and ramifications: contributions to theory and application. In Statistical Distributions in Scientific Work, eds., Taillie, C., Patil, G. P., and Baldessari, B. A., Vol. 4, pp. 19–44. Dordrecht: Reidel.
Barndorff-Nielsen, O. and Blæsild, P (1983). Hyperbolic distributions. In Encyclopedia of Statistical Sciences, eds., Johnson, N. L., Kotz, S. and Read, C. B., Vol. 3, pp. 700–707. New York: Wiley.
dhyperb
, hyperbChangePars
,
besselK
, ghypMom
, ghypMean
,
ghypVar
, ghypSkew
, ghypKurt
Theta <- c(2,2,2,2) hyperbMean(Theta) hyperbVar(Theta) hyperbSkew(Theta) hyperbKurt(Theta) hyperbMode(Theta)
Theta <- c(2,2,2,2) hyperbMean(Theta) hyperbVar(Theta) hyperbSkew(Theta) hyperbKurt(Theta) hyperbMode(Theta)
summary
Method for class "hyperbFit"
.
## S3 method for class 'hyperbFit' summary(object, ...) ## S3 method for class 'summary.hyperbFit' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'hyperbFit' summary(object, ...) ## S3 method for class 'summary.hyperbFit' print(x, digits = max(3, getOption("digits") - 3), ...)
object |
An object of class |
x |
An object of class |
digits |
The number of significant digits to use when printing. |
... |
Further arguments passed to or from other methods. |
summary.hyperbFit
calculates standard errors for the estimates
of ,
,
, and
of the hyperbolic distribution parameter vector Theta if
the Hessian from the call to
optim
or nlm
is available. Because the parameters in the call to the optimiser are
,
,
, and
, the delta method is
used to obtain the standard errors for
and
.
If the Hessian is available, summary.hyperbFit
computes
standard errors for the estimates of ,
,
, and
, and adds them to
object
as object$sds
. Otherwise, no calculations are performed and the
composition of object
is unaltered.
summary.hyperbFit
invisibly returns x
with class changed to summary.hyperbFit
.
See hyperbFit
for the composition of an object of class
hyperbFit
.
print.summary.hyperbFit
prints a summary in the same format as
print.hyperbFit
when the Hessian is not available from
the fit. When the Hessian is available, the standard errors for the
parameter estimates are printed in parentheses beneath the parameter
estimates, in the manner of fitdistr
in the package
MASS
.
### Continuing the hyperbFit(.) example: Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) fit <- hyperbFit(dataVector, method = "BFGS", hessian = TRUE) print(fit) summary(fit)
### Continuing the hyperbFit(.) example: Theta <- c(2,2,2,2) dataVector <- rhyperb(500, Theta) fit <- hyperbFit(dataVector, method = "BFGS", hessian = TRUE) print(fit) summary(fit)