Title: | Tukey g-&-h Distribution |
---|---|
Description: | Functions for density, cumulative density, quantile and simulation of Tukey g-and-h (1977) distributions. The quantile-based transformation (Hoaglin 1985 <doi:10.1002/9781118150702.ch11>) and its reverse transformation, as well as the letter-value based estimates (Hoaglin 1985), are also provided. |
Authors: | Tingting Zhan [aut, cre, cph], Inna Chervoneva [ctb, cph] |
Maintainer: | Tingting Zhan <[email protected]> |
License: | GPL-2 |
Version: | 0.1.3 |
Built: | 2024-12-01 08:37:29 UTC |
Source: | CRAN |
-&-
DistributionDensity, cumulative density, quantile and simulation of
the 4-parameter Tukey (1977) -&-
distributions.
The quantile-based transformation (Hoaglin 1985)
and its reverse transformation,
as well as the letter-value based estimates (Hoaglin 1985),
are also provided.
Returned values of individual functions are documented separately.
Maintainer: Tingting Zhan [email protected] [copyright holder]
Other contributors:
Inna Chervoneva [email protected] [contributor, copyright holder]
Tukey, J.W. (1977): Modern Techniques in Data Analysis. In: NSF-sponsored Regional Research Conference at Southeastern Massachusetts University, North Dartmouth, MA.
Hoaglin, D.C. (1985): Summarizing shape numerically: The -and-
distributions.
Exploring data tables, trends, and shapes, pp. 461–513.
John Wiley & Sons, Ltd, New York.
doi:10.1002/9781118150702.ch11
-&-
TransformationTo transform Tukey -&-
quantiles to standard normal quantiles.
GH2z(q, q0 = (q - A)/B, A = 0, B = 1, ...)
GH2z(q, q0 = (q - A)/B, A = 0, B = 1, ...)
q |
|
q0 |
|
A , B
|
(optional) double scalars, location and scale parameters of
Tukey |
... |
parameters of internal helper function .GH2z |
Unfortunately, function GH2z, the inverse of Tukey -&-
transformation,
does not have a closed form and needs to be solved numerically.
For compute intensive jobs, use internal helper function .GH2z.
Function GH2z returns a double vector of the same length as input q
.
z = rnorm(1e3L) all.equal.numeric(.GH2z(z2GH(z, g = .3, h = .1), g = .3, h = .1), z) all.equal.numeric(.GH2z(z2GH(z, g = 0, h = .1), g = 0, h = .1), z) all.equal.numeric(.GH2z(z2GH(z, g = .2, h = 0), g = .2, h = 0), z)
z = rnorm(1e3L) all.equal.numeric(.GH2z(z2GH(z, g = .3, h = .1), g = .3, h = .1), z) all.equal.numeric(.GH2z(z2GH(z, g = 0, h = .1), g = 0, h = .1), z) all.equal.numeric(.GH2z(z2GH(z, g = .2, h = 0), g = .2, h = 0), z)
-&-
DistributionLetter-value based estimation (Hoaglin, 1985) of
Tukey -,
- and
-&-
distribution.
All equation numbers mentioned below refer to Hoaglin (1985).
letterValue( x, g_ = seq.int(from = 0.15, to = 0.25, by = 0.005), h_ = seq.int(from = 0.15, to = 0.35, by = 0.005), halfSpread = c("both", "lower", "upper"), ... )
letterValue( x, g_ = seq.int(from = 0.15, to = 0.25, by = 0.005), h_ = seq.int(from = 0.15, to = 0.35, by = 0.005), halfSpread = c("both", "lower", "upper"), ... )
x |
|
g_ |
double vector, probabilities used for estimating |
h_ |
double vector, probabilities used for estimating |
halfSpread |
character scalar,
either to use |
... |
additional parameters, currently not in use |
Unexported function letterV_g()
estimates parameter using equation (10) for
-distribution
and the equivalent equation (31) for
-&-
distribution.
Unexported function letterV_B()
estimates parameter for Tukey
-distribution
(i.e.,
,
), using equation (8a) and (8b).
Unexported function letterV_Bh_g()
estimates parameters and
when
, using equation (33).
Unexported function letterV_Bh()
estimates parameters and
for Tukey
-distribution,
i.e., when
and
, using equation (26a), (26b) and (27).
Function letterValue plays a similar role as fitdistrplus:::start.arg.default
,
thus extends fitdistrplus::fitdist
for estimating Tukey -&-
distributions.
Function letterValue returns a 'letterValue'
object,
which is double vector of estimates
for a Tukey
-&-
distribution.
Parameter g_
and h_
does not have to be truly unique; i.e., all.equal elements are allowed.
Hoaglin, D.C. (1985). Summarizing Shape Numerically: The -and-
Distributions.
doi:10.1002/9781118150702.ch11
set.seed(77652); x = rGH(n = 1e3L, g = -.3, h = .1) letterValue(x, g_ = FALSE, h_ = FALSE) letterValue(x, g_ = FALSE) letterValue(x, h_ = FALSE) (m3 = letterValue(x)) library(fitdistrplus) fit = fitdist(x, distr = 'GH', start = as.list.default(m3)) plot(fit) # fitdistrplus:::plot.fitdist
set.seed(77652); x = rGH(n = 1e3L, g = -.3, h = .1) letterValue(x, g_ = FALSE, h_ = FALSE) letterValue(x, g_ = FALSE) letterValue(x, h_ = FALSE) (m3 = letterValue(x)) library(fitdistrplus) fit = fitdist(x, distr = 'GH', start = as.list.default(m3)) plot(fit) # fitdistrplus:::plot.fitdist
-&-
DistributionDensity, distribution function, quantile function and simulation
for Tukey -&-
distribution with
location parameter
,
scale parameter
,
skewness
and
elongation
.
dGH(x, A = 0, B = 1, g = 0, h = 0, log = FALSE, ...) rGH(n, A = 0, B = 1, g = 0, h = 0) qGH(p, A = 0, B = 1, g = 0, h = 0, lower.tail = TRUE, log.p = FALSE) pGH(q, A = 0, B = 1, g = 0, h = 0, lower.tail = TRUE, log.p = FALSE, ...)
dGH(x, A = 0, B = 1, g = 0, h = 0, log = FALSE, ...) rGH(n, A = 0, B = 1, g = 0, h = 0) qGH(p, A = 0, B = 1, g = 0, h = 0, lower.tail = TRUE, log.p = FALSE) pGH(q, A = 0, B = 1, g = 0, h = 0, lower.tail = TRUE, log.p = FALSE, ...)
x , q
|
|
A |
double scalar, location parameter |
B |
double scalar, scale parameter |
g |
double scalar, skewness parameter |
h |
double scalar, elongation parameter |
log , log.p
|
logical scalar, if |
... |
other parameters of function vuniroot2 |
n |
integer scalar, number of observations |
p |
|
lower.tail |
logical scalar, if |
Function dGH returns the density and accommodates vector arguments A
, B
, g
and h
.
The quantiles x
can be either vector or matrix.
This function takes about 1/5 time of gk::dgh
.
Function pGH returns the distribution function, only taking scalar arguments and vector quantiles .
This function takes about 1/10 time of function
gk::pgh
.
Function qGH returns the quantile function, only taking scalar arguments and vector probabilities .
Function rGH generates random deviates, only taking scalar arguments.
(x = c(NA_real_, rGH(n = 5L, g = .3, h = .1))) dGH(x, g = c(0,.1,.2), h = c(.1,.1,.1)) p0 = seq.int(0, 1, by = .2) (q0 = qGH(p0, g = .2, h = .1)) range(pGH(q0, g = .2, h = .1) - p0) q = (-2):3; q[2L] = NA_real_; q (p1 = pGH(q, g = .3, h = .1)) range(qGH(p1, g = .3, h = .1) - q, na.rm = TRUE) (p2 = pGH(q, g = .2, h = 0)) range(qGH(p2, g = .2, h = 0) - q, na.rm = TRUE) curve(dGH(x, g = .3, h = .1), from = -2.5, to = 3.5)
(x = c(NA_real_, rGH(n = 5L, g = .3, h = .1))) dGH(x, g = c(0,.1,.2), h = c(.1,.1,.1)) p0 = seq.int(0, 1, by = .2) (q0 = qGH(p0, g = .2, h = .1)) range(pGH(q0, g = .2, h = .1) - p0) q = (-2):3; q[2L] = NA_real_; q (p1 = pGH(q, g = .3, h = .1)) range(qGH(p1, g = .3, h = .1) - q, na.rm = TRUE) (p2 = pGH(q, g = .2, h = 0)) range(qGH(p2, g = .2, h = 0) - q, na.rm = TRUE) curve(dGH(x, g = .3, h = .1), from = -2.5, to = 3.5)
To solve a monotone function for a given vector of
values.
vuniroot2( y, f, interval = stop("must provide a length-2 `interval`"), tol = .Machine$double.eps^0.25, maxiter = 1000L )
vuniroot2( y, f, interval = stop("must provide a length-2 `interval`"), tol = .Machine$double.eps^0.25, maxiter = 1000L )
y |
|
f |
monotone function |
interval |
|
tol |
double scalar, desired accuracy, i.e., convergence tolerance |
maxiter |
integer scalar, maximum number of iterations |
Function vuniroot2, different from vuniroot, does
accept NA_real_
as element(s) of
handle the case when the analytic root is at lower
and/or upper
return a root of
Inf
(if abs(f(lower)) >= abs(f(upper))
) or
-Inf
(if abs(f(lower)) < abs(f(upper))
),
when the function value f(lower)
and f(upper)
are not of opposite sign.
Function vuniroot2 returns a numeric vector as the solution of
with given vector
.
library(rstpm2) # ?rstpm2::vuniroot does not accept NA \eqn{y} tryCatch(vuniroot(function(x) x^2 - c(NA, 2:9), lower = 1, upper = 3), error = identity) # ?rstpm2::vuniroot not good when the analytic root is at `lower` or `upper` f <- function(x) x^2 - 1:9 vuniroot(f, lower = .99, upper = 3.001) # good tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'no'), warning = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'yes'), warning = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'downX'), error = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'upX'), warning = identity) vuniroot2(c(NA, 1:9), f = function(x) x^2, interval = c(1, 3)) # all good
library(rstpm2) # ?rstpm2::vuniroot does not accept NA \eqn{y} tryCatch(vuniroot(function(x) x^2 - c(NA, 2:9), lower = 1, upper = 3), error = identity) # ?rstpm2::vuniroot not good when the analytic root is at `lower` or `upper` f <- function(x) x^2 - 1:9 vuniroot(f, lower = .99, upper = 3.001) # good tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'no'), warning = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'yes'), warning = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'downX'), error = identity) tryCatch(vuniroot(f, lower = 1, upper = 3, extendInt = 'upX'), warning = identity) vuniroot2(c(NA, 1:9), f = function(x) x^2, interval = c(1, 3)) # all good
-&-
TransformationTo transform standard normal quantiles to Tukey -&-
quantiles.
z2GH(z, A = 0, B = 1, g = 0, h = 0)
z2GH(z, A = 0, B = 1, g = 0, h = 0)
z |
|
A , B , g , h
|
double scalar or vector,
parameters of Tukey |
Function z2GH transforms standard normal quantiles to Tukey -&-
quantiles.
Function z2GH returns a double scalar or vector.
Function gk:::z2gh
is not fully vectorized,
i.e., cannot take vector z
and vector A/B/g/h
,
as of 2023-07-20 (package gk
version 0.6.0)