Title: | The Skew Hyperbolic Student t-Distribution |
---|---|
Description: | Functions are provided for the density function, distribution function, quantiles and random number generation for the skew hyperbolic t-distribution. There are also functions that fit the distribution to data. There are functions for the mean, variance, skewness, kurtosis and mode of a given distribution and to calculate moments of any order about any centre. To assess goodness of fit, there are functions to generate a Q-Q plot, a P-P plot and a tail plot. |
Authors: | David Scott <[email protected]>, Fiona Grimson |
Maintainer: | David Scott <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.4-2 |
Built: | 2024-10-24 20:15:58 UTC |
Source: | https://github.com/r-forge/rmetrics |
This package provides a collection of functions for working with the skew hyperbolic Student t-distribution.
Functions are provided for the density function (dskewhyp
),
distribution function (pskewhyp
), quantiles (qskewhyp
) and
random number generation (rskewhyp
). There are functions that fit
the distribution to data (skewhypFit
). The mean, variance,
skewness, kurtosis and mode can be found using the functions
skewhypMean
, skewhypVar
, skewhypSkew
,
skewhypKurt
and skewhypMode
respectively, and there is
also a function to calculate moments of any order skewhypMom
. To
assess goodness of fit, there are functions to generate a Q-Q plot
(qqskewhyp
) and a P-P plot (ppskewhyp
). S3 methods
print
, plot
and summary
are provided for the output
of skwewhypFit
.
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
Paolella, Marc S. (2007) Intermediate Probability: A Computational Approach, Chichester: Wiley
Scott, D. J., Würtz, D. and Tran, T. T. (2008) Moments of the Generalized Hyperbolic Distribution. Preprint.
dskewhyp
,
skewhypMean
,skewhypMom
,
skewhypFit
, skewhypFitStart
,
qqskewhyp
,
GeneralizedHyperbolicDistribution
.
Data on 102 male and 100 female athletes collected at the Australian Institute of Sport, courtesy of Richard Telford and Ross Cunningham.
data(ais)
data(ais)
A data frame with 202 observations on 13 variables.
[, 1] | sex | sex |
[, 2] | sport | sport |
[, 3] | rcc | red cell count |
[, 4] | wcc | white cell count |
[, 5] | Hc | Hematocrit |
[, 6] | Hg | Hemoglobin |
[, 7] | Fe | plasma ferritin concentration |
[, 8] | bmi | body mass index, weight/(height) |
[, 9] | ssf | sum of skin folds |
[,10] | Bfat | body fat percentage |
[,11] | lbm | lean body mass |
[,12] | Ht | height (cm) |
[,13] | Wt | weight (Kg) |
Cook and Weisberg (1994) via the package sn. This help file is a modification of the help file from the package sn.
Cook and Weisberg (1994), An Introduction to Regression Graphics. John Wiley & Sons, New York.
data(ais) Fe <- ais$Fe ### Not enough data to find starting values ### Use default parameter values as starting values FeFit <- skewhypFit(Fe, startValues = "US", paramStart = c(0,1,1,1)) ### Ferritin must always be non-negative ### Probability of negative values is small for fitted distribution pskewhyp(0, param = FeFit$param)
data(ais) Fe <- ais$Fe ### Not enough data to find starting values ### Use default parameter values as starting values FeFit <- skewhypFit(Fe, startValues = "US", paramStart = c(0,1,1,1)) ### Ferritin must always be non-negative ### Probability of negative values is small for fitted distribution pskewhyp(0, param = FeFit$param)
Log returns of daily closing value data from the dow jones index, from 04/JAN/1999 to 08/JUL/2003. The original data used to calculate these was the dji data set available in the QRMlib package.
data(lrdji)
data(lrdji)
A vector of 1132 observations.
David Scott [email protected], Fiona Grimson
library(QRMlib) data(dji)
McNeil, A. & Ulman, S. (2008). QRMlib http://cran.r-project.org/web/packages/QRMlib/index.html
data(lrdji) ##fit a skew hyperbolic student t-distribution to the data fit <- skewhypFit(lrdji, plot = TRUE, print = TRUE)
data(lrdji) ##fit a skew hyperbolic student t-distribution to the data fit <- skewhypFit(lrdji, plot = TRUE, print = TRUE)
Log returns of daily closing value data of the NOK/EUR (Norwegian Kroner/Euro) exchange rate, from 04/JAN/1999 to 08/JUL/2003. The original data was downloaded from the oanda website. The data was selected to be as similar as possible to the data used in the Aas & Haff article (see References).
data(lrnokeur)
data(lrnokeur)
A vector of 1647 observations.
David Scott [email protected], Fiona Grimson
http://www.oanda.com
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
##Fit the skew hyperbolic students-t distribution to the data data(lrnokeur) fit <- skewhypFit(lrnokeur, method = "nlm", plot = TRUE, print = TRUE)
##Fit the skew hyperbolic students-t distribution to the data data(lrnokeur) fit <- skewhypFit(lrnokeur, method = "nlm", plot = TRUE, print = TRUE)
Given the parameter vector param
, or parameter values of a skew
hyperbolic Student t-distribution, this function determines the
range outside of which the density function or distribution function
are negligible, to a specified tolerance.
skewhypCalcRange(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), density = TRUE, tol= 10^(-5), ...) skewhypStepSize(dist, delta, beta, nu, side = c("right","left"))
skewhypCalcRange(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), density = TRUE, tol= 10^(-5), ...) skewhypStepSize(dist, delta, beta, nu, side = c("right","left"))
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form |
density |
Logical. If |
tol |
Density function value at the endpoints of the range returned by the function. |
dist |
Numeric. Current distance value. |
side |
Character. |
... |
Passes additional arguments to |
The particular skew hyperbolic distribution being considered is
specified by either the individual parameter values, or the parameter
vector param
. If both are specified, the values in param
will overwriete the other ones. In addition the parameter values are
examined by calling the function skewhypCheckPars
to see if
they are valid.
The function skewhypCalcRange
returns the range outside of
which the density function or distribution function are less than the
given tolerance. The points are found by using uniroot
on the density or distribution function.
The function skewhypStepSize
is used for stepping to the right
or the left to obtain an enclosing interval so uniroot
can be
used to search. When the tail is declining exponentially the step is
just a linear function of the current distance from the mode. If the
tail is declining only as a power of , an exponential step is
used.
skewhypStepSize
is for internal use and is not expected to be
called by users. It is documented here for completeness.
The function skewhypCalcRange
returns a two component vector
giving the lower and upper limits of the range.
skewhypStepSize
returns the size of the step.
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
uniroot
, dskewhyp
, skewhypCheckPars
param <- c(0,1,10,10) range <- skewhypCalcRange(param = param, tol = 10^(-2)) range curve(dskewhyp(x, param = c(0,1,5,10), range[1], range[2])) param <- c(0,1,20,1) (range <- skewhypCalcRange(param = param)) round(integrate(dskewhyp, -Inf, range[1], param = param)$value,7) round(integrate(dskewhyp, range[2], Inf, param = param)$value,7)
param <- c(0,1,10,10) range <- skewhypCalcRange(param = param, tol = 10^(-2)) range curve(dskewhyp(x, param = c(0,1,5,10), range[1], range[2])) param <- c(0,1,20,1) (range <- skewhypCalcRange(param = param)) round(integrate(dskewhyp, -Inf, range[1], param = param)$value,7) round(integrate(dskewhyp, range[2], Inf, param = param)$value,7)
Given a set of parameters for the skew hyperbolic Student t-distribution, the function checks that the parameters are in the correct range, and that the set has the correct length of 4.
skewhypCheckPars(param)
skewhypCheckPars(param)
param |
A numeric vector of proposed parameters for the skew hyperbolic t-distribution. |
The vector param
should be of the form
c(mu,delta,beta,nu)
.
If either delta
or nu
is not greater than zero an error
message is returned.
If the vector param
does not have a length of 4 then an error
message is returned.
A list with components:
case |
Either |
errMessage |
An appropriate error message if an error was found, otherwise an empty string. |
David Scott [email protected], Fiona Grimson
skewhypCheckPars(c(0,1,1,1)) #normal skewhypCheckPars(c(0,0,1,1)) #error skewhypCheckPars(c(0,1,1,-1)) #error skewhypCheckPars(c(0,1,1)) #error
skewhypCheckPars(c(0,1,1,1)) #normal skewhypCheckPars(c(0,0,1,1)) #error skewhypCheckPars(c(0,1,1,-1)) #error skewhypCheckPars(c(0,1,1)) #error
Density function, distribution function, quantiles and random number
generation for the skew hyperbolic Student t-distribution, with
parameters (skewness),
(scale),
(location) and
(shape). Also a
function for the derivative of the density function.
dskewhyp(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), log = FALSE, tolerance = .Machine$double.eps^0.5) pskewhyp(q, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu, delta, beta, nu), log.p = FALSE, lower.tail = TRUE, subdivisions = 100, intTol = .Machine$double.eps^0.25, valueOnly = TRUE, ...) qskewhyp(p, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta, beta, nu), lower.tail = TRUE, log.p = FALSE, method = c("spline","integrate"), nInterpol = 501, uniTol = .Machine$double.eps^0.25, subdivisions = 100, intTol = uniTol, ...) rskewhyp(n, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), log = FALSE) ddskewhyp(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu),log = FALSE, tolerance = .Machine$double.eps^0.5)
dskewhyp(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), log = FALSE, tolerance = .Machine$double.eps^0.5) pskewhyp(q, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu, delta, beta, nu), log.p = FALSE, lower.tail = TRUE, subdivisions = 100, intTol = .Machine$double.eps^0.25, valueOnly = TRUE, ...) qskewhyp(p, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta, beta, nu), lower.tail = TRUE, log.p = FALSE, method = c("spline","integrate"), nInterpol = 501, uniTol = .Machine$double.eps^0.25, subdivisions = 100, intTol = uniTol, ...) rskewhyp(n, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), log = FALSE) ddskewhyp(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu),log = FALSE, tolerance = .Machine$double.eps^0.5)
x , q
|
Vector of quantiles. |
p |
Vector of probabilities. |
n |
Number of random variates to be generated. |
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form |
log , log.p
|
Logical; if |
method |
Character. If |
lower.tail |
Logical. If |
tolerance |
Specified level of tolerance when checking if
parameter |
subdivisions |
The maximum number of subdivisions used to integrate the density and determine the accuracy of the distribution function calculation. |
intTol |
Value of |
valueOnly |
Logical. If |
nInterpol |
Number of points used in |
uniTol |
Value of |
... |
Passes additional arguments to |
Users may either specify the values of the parameters individually or
as a vector. If both forms are specified, then the values specified by
the vector param
will overwrite the other ones. In addition the
parameter values are examined by calling the function
skewhypCheckPars
to see if they are valid.
The density function is
when , and
when , where
is the
modified Bessel function of the third kind with order
,
and
is the gamma function.
pskewhyp
uses the function integrate
to
numerically integrate the density function. The integration is from
-Inf
to x
if x
is to the left of the mode, and
from x
to Inf
if x
is to the right of the
mode. The probability calculated this way is subtracted from 1 if
required. Integration in this manner appears to make calculation of
the quantile function more stable in extreme cases.
Calculation of quantiles using qhyperb
permits the use of two
different methods. Both methods use uniroot
to find the value
of for which a given
is equal
where
denotes the cumulative distribution function. The difference is in how
the numerical approximation to
is obtained. The obvious
and more accurate method is to calculate the value of
whenever it is required using a call to
phyperb
. This is what
is done if the method is specified as "integrate"
. It is clear
that the time required for this approach is roughly linear in the
number of quantiles being calculated. A Q-Q plot of a large data set
will clearly take some time. The alternative (and default) method is
that for the major part of the distribution a spline approximation to
is calculated and quantiles found using
uniroot
with
this approximation. For extreme values (for which the tail probability
is less than ), the integration method is still
used even when the method specifed is
"spline"
.
If accurate probabilities or quantiles are required, tolerances
(intTol
and uniTol
) should be set to small values, say
or
with
method
= "integrate"
. Generally then accuracy might be expected to be at
least . If the default values of the functions
are used, accuracy can only be expected to be around
. Note that on 32-bit systems
.Machine$double.eps^0.25 = 0.0001220703
is a typical value.
Note that when small values of are used, and the density
is skewed, there are often some extreme values generated by
rskewhyp
. These look like outliers, but are caused by the
heaviness of the skewed tail, see Examples.
The extreme skewness of the distribution when is
large in absolute value and
is small make this
distribution very challenging numerically.
dskewhyp
gives the density function, pskewhyp
gives the
distribution function, qskewhyp
gives the quantile function and
rskewhyp
generates random variates.
An estimate of the accuracy of the approximation to the distribution
function can be found by setting valueOnly = FALSE
in the call to
pskewyhp
which returns a list with components value
and
error
.
ddskewhyp
gives the derivative of dskewhyp
.
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
safeIntegrate
,
integrate
for its shortfalls,
skewhypCheckPars
,
logHist
. Also
skewhypMean
for information on moments and mode, and
skewhypFit
for fitting to data.
param <- c(0,1,40,10) par(mfrow = c(1,2)) range <- skewhypCalcRange(param = param, tol = 10^(-2)) ### curves of density and distribution curve(dskewhyp(x, param = param), range[1], range[2], n = 1000) title("Density of the \n Skew Hyperbolic Distribution") curve(pskewhyp(x, param = param), range[1], range[2], n = 500) title("Distribution Function of the \n Skew Hyperbolic Distribution") ### curves of density and log density par(mfrow = c(1,2)) data <- rskewhyp(1000, param = param) curve(dskewhyp(x, param = param), range(data)[1], range(data)[2], n = 1000, col = 2) hist(data, freq = FALSE, add = TRUE) title("Density and Histogram of the\n Skew Hyperbolic Distribution") DistributionUtils::logHist(data, main = "Log-Density and Log-Histogram of\n the Skew Hyperbolic Distribution") curve(dskewhyp(x, param = param, log = TRUE), range(data)[1], range(data)[2], n = 500, add = TRUE, col = 2) ##plots of density and derivative par(mfrow = c(2,1)) curve(dskewhyp(x, param = param), range[1], range[2], n = 1000) title("Density of the Skew\n Hyperbolic Distribution") curve(ddskewhyp(x, param = param), range[1], range[2], n = 1000) title("Derivative of the Density\n of the Skew Hyperbolic Distribution") ## example of density and random numbers for beta large and nu small par(mfrow = c(1,2)) param1 <- c(0,1,10,1) data1 <- rskewhyp(1000, param = param1) curve(dskewhyp(x, param = param1), range(data1)[1], range(data1)[2], n = 1000, col = 2, main = "Density and Histogram -- when nu is small") hist(data1, freq = FALSE, add = TRUE) DistributionUtils::logHist(data1, main = "Log-Density and Log-Histogram -- when nu is small") curve(dskewhyp(x, param = param1, log = TRUE), from = min(data1), to = max(data1), n = 500, add = TRUE, col = 2)
param <- c(0,1,40,10) par(mfrow = c(1,2)) range <- skewhypCalcRange(param = param, tol = 10^(-2)) ### curves of density and distribution curve(dskewhyp(x, param = param), range[1], range[2], n = 1000) title("Density of the \n Skew Hyperbolic Distribution") curve(pskewhyp(x, param = param), range[1], range[2], n = 500) title("Distribution Function of the \n Skew Hyperbolic Distribution") ### curves of density and log density par(mfrow = c(1,2)) data <- rskewhyp(1000, param = param) curve(dskewhyp(x, param = param), range(data)[1], range(data)[2], n = 1000, col = 2) hist(data, freq = FALSE, add = TRUE) title("Density and Histogram of the\n Skew Hyperbolic Distribution") DistributionUtils::logHist(data, main = "Log-Density and Log-Histogram of\n the Skew Hyperbolic Distribution") curve(dskewhyp(x, param = param, log = TRUE), range(data)[1], range(data)[2], n = 500, add = TRUE, col = 2) ##plots of density and derivative par(mfrow = c(2,1)) curve(dskewhyp(x, param = param), range[1], range[2], n = 1000) title("Density of the Skew\n Hyperbolic Distribution") curve(ddskewhyp(x, param = param), range[1], range[2], n = 1000) title("Derivative of the Density\n of the Skew Hyperbolic Distribution") ## example of density and random numbers for beta large and nu small par(mfrow = c(1,2)) param1 <- c(0,1,10,1) data1 <- rskewhyp(1000, param = param1) curve(dskewhyp(x, param = param1), range(data1)[1], range(data1)[2], n = 1000, col = 2, main = "Density and Histogram -- when nu is small") hist(data1, freq = FALSE, add = TRUE) DistributionUtils::logHist(data1, main = "Log-Density and Log-Histogram -- when nu is small") curve(dskewhyp(x, param = param1, log = TRUE), from = min(data1), to = max(data1), n = 500, add = TRUE, col = 2)
qqskewhyp
produces a skew hyperbolic t-distribution Q-Q
plot of the values in y
, ppskewhyp
produces a skew
hyperbolic t-distribution P-P (percent-percent) plot or
probability plot of the values in y
. Graphical parameters may
be given as arguments to qqskewhyp
and ppskewhyp
.
qqskewhyp(y, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu, delta, beta, nu), main = "Skew Hyperbolic Student-t QQ Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppskewhyp(y, beta = NULL, delta = NULL, mu = NULL, nu = NULL, param = c(mu, delta, beta, nu), main = "Skew Hyperbolic Student-t P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
qqskewhyp(y, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu, delta, beta, nu), main = "Skew Hyperbolic Student-t QQ Plot", xlab = "Theoretical Quantiles", ylab = "Sample Quantiles", plot.it = TRUE, line = TRUE, ...) ppskewhyp(y, beta = NULL, delta = NULL, mu = NULL, nu = NULL, param = c(mu, delta, beta, nu), main = "Skew Hyperbolic Student-t P-P Plot", xlab = "Uniform Quantiles", ylab = "Probability-integral-transformed Data", plot.it = TRUE, line = TRUE, ...)
y |
The sample data. |
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form |
main , xlab , ylab
|
Plot labels. |
plot.it |
Logical; if |
line |
Logical; if |
... |
Further graphical parameters. |
Users may either specify the values of the parameters individually or
as a vector. If both forms are specified, then the values specified by
the vector param
will overwrite the other ones.
For qqskewhyp
and ppskewhyp
, a list with components:
x |
The x coordinates of the points to be plotted. |
y |
The y coordinates of the points to be plotted. |
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
par(mfrow = c(1,2)) param <- c(0,1,0,10) y <- rskewhyp(500, param = param) qqskewhyp(y, param = param, main = "Skew Hyperbolic\n Q-Q Plot") ppskewhyp(y, param = param, main = "Skew Hyperbolic\n P-P Plot")
par(mfrow = c(1,2)) param <- c(0,1,0,10) y <- rskewhyp(500, param = param) qqskewhyp(y, param = param, main = "Skew Hyperbolic\n Q-Q Plot") ppskewhyp(y, param = param, main = "Skew Hyperbolic\n P-P Plot")
Fits a skew hyperbolic t-distribution to given data. Displays the histogram, log-histogram (both with fitted densities), Q-Q plot and P-P plot for the fit which has maximum likelihood.
skewhypFit(x, freq = NULL, breaks = NULL, startValues = "LA", paramStart = NULL, method = "Nelder-Mead", hessian = TRUE, plots = FALSE, printOut = TRUE, controlBFGS = list(maxit = 200), controlNM = list(maxit = 1000), maxitNLM = 1500, ...) ## S3 method for class 'skewhypFit' 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(), ...) ## S3 method for class 'skewhypFit' print(x,digits = max(3, getOption("digits") - 3),...)
skewhypFit(x, freq = NULL, breaks = NULL, startValues = "LA", paramStart = NULL, method = "Nelder-Mead", hessian = TRUE, plots = FALSE, printOut = TRUE, controlBFGS = list(maxit = 200), controlNM = list(maxit = 1000), maxitNLM = 1500, ...) ## S3 method for class 'skewhypFit' 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(), ...) ## S3 method for class 'skewhypFit' print(x,digits = max(3, getOption("digits") - 3),...)
x |
Data vector for |
freq |
Vector of weights with length equal to length of |
breaks |
Breaks for histogram, defaults to those generated by
|
startValues |
Code giving the method of determining starting values for finding the maximum likelihood estimates of the parameters. |
paramStart |
If |
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 |
which |
If a subset of plots is required, specify a subset of the
numbers |
plotTitles |
Titles to appear above the plots. |
ask |
Logical; if |
digits |
Desired number of digits when the object is printed. |
... |
Passes arguments to |
startValues
can be either "US"
(User-supplied) or
"LA"
(Linear approximation)
If startValues = "US"
then a value for paramStart
must be
supplied. For the details concerning the use of startValues
and paramStart
see skewhypFitStart
.
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 the details of how to pass control information using
optim
and nlm
, see optim
and
nlm.
skewhypFit
returns a list with components:
param |
A vector giving the maximum likelihood estimates of the
parameters in the form |
maxLik |
The value of the maximised log-likelihood. |
hessian |
If |
method |
Optimisation method used. |
conv |
|
iter |
Number of iterations of optimisation routine. |
x |
The data used to fit the distribution. |
xName |
Character string with the actual |
paramStart |
Starting values of the parameters returned by
|
svName |
Name of the method used to find starting values. |
startValues |
Acronym of method used to find starting values. |
breaks |
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], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
optim
, nlm
, par
,
hist
, density,
logHist
,
qqskewhyp
, ppskewhyp
,
dskewhyp
and skewhypFitStart
.
## See how well skewhypFit works param <- c(0, 1, 4, 10) data <- rskewhyp(500, param = param) fit <- skewhypFit(data) ## Use data set NOK/EUR as per Aas&Haff data(lrnokeur) nkfit <- skewhypFit(lrnokeur, method = "nlm") ## Use data set DJI data(lrdji) djfit <- skewhypFit(lrdji)
## See how well skewhypFit works param <- c(0, 1, 4, 10) data <- rskewhyp(500, param = param) fit <- skewhypFit(data) ## Use data set NOK/EUR as per Aas&Haff data(lrnokeur) nkfit <- skewhypFit(lrnokeur, method = "nlm") ## Use data set DJI data(lrdji) djfit <- skewhypFit(lrdji)
Finds starting values for input to a maximum likelihood routine for fitting a skew hyperbolic t-distribution to data.
skewhypFitStart(x, breaks = NULL, startValues = "LA", paramStart = NULL, ...) skewhypFitStartLA(x, breaks = NULL) skewhypFitStartMM(x, nuTol = 1e-6, nuStart = 5, ...)
skewhypFitStart(x, breaks = NULL, startValues = "LA", paramStart = NULL, ...) skewhypFitStartLA(x, breaks = NULL) skewhypFitStartMM(x, nuTol = 1e-6, nuStart = 5, ...)
x |
Data vector. |
breaks |
Breaks for histogram. If missing defaults to those
generated by |
startValues |
Code giving the method of determining starting values for finding the maximum likelihood estimates of the parameters. |
paramStart |
If |
nuTol |
Tolerance for numerical determination of |
nuStart |
Initial value for numerical determinationof |
... |
Passes additional arguments to |
startValues
can be either "US"
(User-supplied),
"LA"
(Linear approximation), or "MM"
(Method of moments).
If startValues = "US"
then a value for paramStart
must be
supplied. The parameters are checked for validity by the function
skewhypCheckPars
.
If startValues = "LA"
a linear approximation is made to the
log-density in each of the tails, from which the estimates for
and
are found. The remaining two
parameters,
and
are found by solving
the moment equations for mean and variance. Since the variance does
not exist for values of
, the estimate of
will be at least 4.1. Note that if the distribution is
too skewed, there are not enough points in the lighter tail to fit the
required linear model, and the method will stop and return a
warning. User supplied values will have to be used in this case.
If startValues = "MM"
, start values are found using the method
of moments as outlined in Aas and Haff (2006).
skewhypFitStart
returns a list with components:
paramStart |
A vector of the form |
breaks |
The cell boundaries found by a call to |
midpoints |
The cell midpoints found by a call to |
empDens |
The estimated density at the midpoints found by a call
to |
svName |
Name of the method used to find the starting values. |
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
hist
, density
, dskewhyp
,
skewhypFit
, skewhypCheckPars
## find starting values to feed to skewhypFit data(lrnokeur) skewhypFitStart(lrnokeur, startValues="LA")$paramStart ## user supplied values skewhypFitStart(lrnokeur, startValues="US", paramStart=c(0,0.01,0,5))$paramStart
## find starting values to feed to skewhypFit data(lrnokeur) skewhypFitStart(lrnokeur, startValues="LA")$paramStart ## user supplied values skewhypFitStart(lrnokeur, startValues="US", paramStart=c(0,0.01,0,5))$paramStart
Functions to calculate the mean, variance, skewness, kurtosis and mode of a specified skew hyperbolic t-distribution.
skewhypMean(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypVar(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypSkew(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypKurt(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypMode(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), tolerance = .Machine$double.eps ^ 0.5)
skewhypMean(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypVar(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypSkew(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypKurt(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu)) skewhypMode(mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), tolerance = .Machine$double.eps ^ 0.5)
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form |
tolerance |
A difference smaller than this value is taken to be zero. |
Users may either specify the values of the parameters individually or
as a vector. If both forms are specified, then the values specified by
the vector param
will overwrite the other ones.In addition the
parameter values are examined by calling the function
skewhypCheckPars
to see if they are valid.
The moments are calculated as per formulae in Aas&Haff(2006) and the
mode is calculated by numerical optimisation of the density function
using optim
.
Note that the mean does not exist when , the
variance does not exist for
, the skewness
does not exist for
, and the kurtosis does not
exist for
.
skewhypMean
gives the mean of the skew hyperbolic
t-distribution, skewhypVar
the variance,
skewhypSkew
the skewness, skewhypKurt
the kurtosis and
skewhypMode
the mode.
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
dskewhyp
, optim
,
skewhypCheckPars
, skewhypMom
param <- c(10,1,5,9) skewhypMean(param = param) skewhypVar(param = param) skewhypSkew(param = param) skewhypKurt(param = param) skewhypMode(param = param) range <- skewhypCalcRange(param = param) curve(dskewhyp(x, param = param), range[1], range[2]) abline(v = skewhypMode(param = param), col = "red") abline(v = skewhypMean(param = param), col = "blue")
param <- c(10,1,5,9) skewhypMean(param = param) skewhypVar(param = param) skewhypSkew(param = param) skewhypKurt(param = param) skewhypMode(param = param) range <- skewhypCalcRange(param = param) curve(dskewhyp(x, param = param), range[1], range[2]) abline(v = skewhypMode(param = param), col = "red") abline(v = skewhypMean(param = param), col = "blue")
This function can be used to calculate the raw moments, mu moments, central moments, and moments about any other given location for the skew hyperbolic t-distribution.
skewhypMom(order, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), momType = "raw", about = 0)
skewhypMom(order, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), momType = "raw", about = 0)
order |
Numeric. The order of the moment to be calculated. Not permitted to be a vector. Must be a positive integer, except for moments about 0. |
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form
|
momType |
Common types of moments to be calculated, default is
|
about |
Numeric. The point around which the moment is to be calculated, default is zero. See Details. |
Users may either specify the values of the parameters individually or
as a vector. If both forms are specified, then the values specified by
the vector param
will overwrite the other ones. In addition the
parameter values are examined by calling the function
skewhypCheckPars
to see if they are valid.
order
is also checked by calling the function
is.wholenumber
in the DistributionUtils
package to
see whether a whole number is given.
momType
can be either "raw"
(moments about zero),
"mu"
(moments about mu), or "central"
(moments
about the mean). If one of these types of moments is required there is
no need to specify a value for about
. For moments about any
other location about
must be specified. In the case that both
momType
and about
are specified and contradicting, the
function will calculate the moments based on the value of
about
.
To calculate the moments of the skew hyperbolic t-distribution,
the function first calculates the mu moments by the formula defined
below, and then transforms them to any of the other types of moment by
calling momChangeAbout
in the DistributionUtils
package.
The mu moments of the skew hyperbolic t-distribution are given by:
where and
and
is the recursive coefficient (see
momRecursion
for details).
This formula is given in Scott, Würtz and Tran
(2008). Note that the [.] part of this formula is actually equivalent
to the formula for the raw moments of the inverse gamma distribution,
so the function calls gammaRawMom
in the GeneralizedHyperbolic
package when implementing the computations.
The function returns the moment specified. In the case of raw moments,
Inf
is returned if the moment is infinite.
David Scott [email protected], Fiona Grimson
Paolella, Marc S. (2007) Intermediate Probability: A Computational Approach, Chichester: Wiley
Scott, D. J., Würtz, D. and Tran, T. T. (2008) Moments of the Generalized Hyperbolic Distribution. Preprint.
skewhypCheckPars
, skewhypMean
,
is.wholenumber
,
momRecursion
,
momChangeAbout
and
gigMom
.
param = c(1,2,3,10) ##Raw moments of the skew hyperbolic t distribution skewhypMom(3, param = param, momType = "raw") ##Mu moments skewhypMom(3, param = param, momType = "mu") ##Central moments skewhypMom(3, param = param, momType = "central") ##Moments about any location skewhypMom(3, param = param, about = 5)
param = c(1,2,3,10) ##Raw moments of the skew hyperbolic t distribution skewhypMom(3, param = param, momType = "raw") ##Mu moments skewhypMom(3, param = param, momType = "mu") ##Central moments skewhypMom(3, param = param, momType = "central") ##Moments about any location skewhypMom(3, param = param, about = 5)
These objects store different parameter sets of the skew hyperbolic
distribution for testing or demonstrating purpose as matrices.
Specifically, the parameter sets skewhypSmallShape
and
skewhypLargeShape
have constant location parameter of and scale parameter of
.
The skewness parameter takes values from {0,2} in
skewhypSmallShape
and skewhypSmallParam
, and from
{-5,0,1,2,5} in skewhypLargeShape
and
skewhypLargeParam
.
The shape parameter takes values from {1,5} in
skewhypSmallShape
and skewhypSmallParam
, and from
{1,2,5,10,20} in skewhypLargeShape
and
skewhypLargeParam
.
data(skewhypParam)
data(skewhypParam)
skewhypSmallShape
: a 4 by 4 matrix;
skewhypLargeShape
: a 25 by 4 matrix;
skewhypSmallParam
: a 16 by 4 matrix;
skewhypLargeParam
: a 400 by 4 matrix.
David Scott [email protected]
data(skewhypParam) ### Testing the accuracy of skewhypMean for (i in 1:nrow(skewhypSmallParam)) { param <- skewhypSmallParam[i, ] x <- rskewhyp(1000, param = param) sampleMean <- mean(x) distMean <- skewhypMean(param = param) difference <- abs(sampleMean - distMean) print(difference) }
data(skewhypParam) ### Testing the accuracy of skewhypMean for (i in 1:nrow(skewhypSmallParam)) { param <- skewhypSmallParam[i, ] x <- rskewhyp(1000, param = param) sampleMean <- mean(x) distMean <- skewhypMean(param = param) difference <- abs(sampleMean - distMean) print(difference) }
Adds skew hyperbolic t-distribution line to a tail plot
skewhypTailPlotLine(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), side = c("right", "left"), ...)
skewhypTailPlotLine(x, mu = 0, delta = 1, beta = 1, nu = 1, param = c(mu,delta,beta,nu), side = c("right", "left"), ...)
x |
A vector of values for which the tail plot has been drawn. |
side |
Character. |
mu |
Location parameter |
delta |
Scale parameter |
beta |
Skewness parameter |
nu |
Shape parameter |
param |
Specifying the parameters as a vector of the form |
... |
Other graphical parameters (see |
The function tailPlot
from DistributionUtils can be used
to draw either a left-hand or right-hand tail plot of
the data x
. See for example Resnick (2007), p.105. The
left-hand tail plot plots the empirical distribution of the data
against the order statistics, for order statistic values below the
median. The right-hand tail plot plots one minus the empirical
distribution of the data against the order statistics, for order
statistic values above the median. The default is for the y-axis to be
plotted on a log scale.
skewhypTailPlotLine
adds the line derived from the given skew
hyperbolic t-distribution to an already drawn tail plot.
Returns NULL
invisibly.
David Scott [email protected]
Aas, Kjersti and Hobæk Haff, Ingrid (2006)
The generalised hyperbolic skew Student's -distribution.
Journal of Financial Econometrics, 4, 275–309.
Resnick, S. (2007) Heavy-Tail Phenomena, New York: Springer.
tailPlot
and
skewhypFit
.
### Draw tail plot of some data tailPlot <- DistributionUtils :: tailPlot ## for convenience below param <- c(0,1,1,10) x <- rskewhyp(200, param = param) tailPlot(x) ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = param) ### Parameters from fit may look better paramFit <- skewhypFit(x, plots = FALSE)$param tailPlot(x) skewhypTailPlotLine(x, param = param) skewhypTailPlotLine(x, param = paramFit, col = "steelblue") ### Left tail example tailPlot(x, side = "l") ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = paramFit, side = "l") ### Log scale on both axes tailPlot(x, side = "r", log = "xy") ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = paramFit, side = "r")
### Draw tail plot of some data tailPlot <- DistributionUtils :: tailPlot ## for convenience below param <- c(0,1,1,10) x <- rskewhyp(200, param = param) tailPlot(x) ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = param) ### Parameters from fit may look better paramFit <- skewhypFit(x, plots = FALSE)$param tailPlot(x) skewhypTailPlotLine(x, param = param) skewhypTailPlotLine(x, param = paramFit, col = "steelblue") ### Left tail example tailPlot(x, side = "l") ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = paramFit, side = "l") ### Log scale on both axes tailPlot(x, side = "r", log = "xy") ### Add skew hyperbolic t-distribution line skewhypTailPlotLine(x, param = paramFit, side = "r")
summary
Method for class "skewhypFit"
.
## S3 method for class 'skewhypFit' summary(object, ...) ## S3 method for class 'summary.skewhypFit' print(x, digits = max(3, getOption("digits") - 3), ...)
## S3 method for class 'skewhypFit' summary(object, ...) ## S3 method for class 'summary.skewhypFit' 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.skewhypFit
calculates standard errors for errors for
the estimates of ,
,
and
of the skew hyperbolic Student
t-distribution parameter vector
param
, 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 standard
errors for
and
If the Hessian is available summary.skewhyhpFit
computes
standard errors of ,
,
and
, and adds them to
object
as
object$sds
. Otherwise, no calculations are performed and the
composition object
is unaltered.
summary.skewhypFit
invisibly returns x
with class
changed to summary.skewhypFit
.
See skewhypFit
for the composition of an object of class
skewhypFit
.
print.summary.skewhypFit
prints a summary in the same format as
print.skewhypFit
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
.
David Scott [email protected], Fiona Grimson
Aas, K. and Haff, I. H. (2006). The Generalised Hyperbolic Skew Student's t-distribution, Journal of Financial Econometrics, 4, 275–309.
## Continuing the skewhypFit(.) example: data(lrdji) djfit <- skewhypFit(lrdji, print = FALSE, plot = FALSE, hessian = TRUE) print(djfit) summary(djfit)
## Continuing the skewhypFit(.) example: data(lrdji) djfit <- skewhypFit(lrdji, print = FALSE, plot = FALSE, hessian = TRUE) print(djfit) summary(djfit)