nvmix (version 0.0-3)

gammamix: Functionalities for Gamma Scale Mixture Models

Description

Evaluating density-, distribution- and quantile-function of Gamma scale mixtures as well as random variate generation.

Usage

dgammamix(x, qmix, d, control = list(), verbose = TRUE, log = FALSE, ...)
pgammamix(x, qmix, d, lower.tail = TRUE, control = list(), verbose = TRUE, ...)
qgammamix(u, qmix, d, control = list(), verbose = TRUE, q.only = TRUE,
          stored.values = NULL, ...)
rgammamix(n, rmix = NULL, qmix = NULL, d, method = c("PRNG", "sobol", "ghalton"),
          skip = 0, ...)

Arguments

x

\(n\)-vector of evaluation points.

u

\(n\)-vector of probabilities.

qmix

see pnvmix().

rmix

see rnvmix().

d

dimension of the underlying normal variance mixture, see also details below.

n

sample size \(n\) (positive integer).

lower.tail

logical; if TRUE (default), probabilities are \(P(X<= x)\), otherwise \(P(X > x)\).

log

logical indicating whether the log-density shall be returned.

q.only

see qnvmix().

stored.values

see qnvmix().

method

see rnvmix().

skip

see rnvmix().

control

list specifying algorithm specific parameters; see get_set_param().

verbose

logical indicating whether a warning is given if the required precision has not been reached.

additional arguments (for example, parameters) passed to the underlying mixing distribution when qmix is a character string or function.

Value

pgammamix() and dgammamix() return a numeric \(n\)-vector with the computed probabilities/densities and corresponding attributes "error" (error estimates of the RQMC estimator) and "numiter" (number of iterations).

If q.only = TRUE, qgammamix() a vector of the same length as u with entries \(q_i\) where \(q_i\) satisfies \(q_i = inf_x { F(x) >= u_i}\) where \(F(x)\) the df of the Gamma mixture specified via qmix; if q.only = FALSE, see qnvmix.

rgammamix() returns a \(n\)-vector containing \(n\) samples of the specified (via mix) Gamma mixture.

Details

We define a Gamma mixture as a random variable \(Dsq\) satisfying, in distribution, \(Dsq = W*Gamma(d/2, 2)\) where \(W\) is specified via qmix. If \(X\) follows a \(d-\)dimensional normal variance mixture, the squared Mahalanobis distance \((X-\mu)^T Sigma^{-1}(X-\mu)\) has the same distribution as \(Dsq\).

The functions presented here are similar to the corresponding functions for normal variance mixtures (d/p/q/rnvmix()), details can be found in the corresponding help-files there.

References

Hintz, E., Hofert, M. and Lemieux, C. (2019), Normal variance mixtures: Distribution, density and parameter estimation. https://arxiv.org/abs/1911.03017.

See Also

dnvmix(), pnvmix(), qnvmix(), rnvmix(), get_set_param(), qqplot_maha(), fitnvmix()

Examples

Run this code
# NOT RUN {
## Specify inverse-gamma mixture => results in d * F(d, nu) dist'n,
## handled correctly when 'qmix = "inverse.gamma"' is specified
qmix <- function(u, nu) 1/qgamma(1 - u, shape = nu/2, rate = nu/2)

## Example for rgammamix()
set.seed(271) # for reproducibility
n  <- 25
nu <- 3
d  <- 5
x  <- rgammamix(n, qmix = qmix, d = d, nu = nu)

## Evaluate distribution function at 'x'
p.true_1 <- pgammamix(x, qmix = "inverse.gamma", d = d, df = nu) # calls pf(...)
p.true_2 <- pf(x/d, df1 = d, df2 = nu) 
p.estim  <- pgammamix(x, qmix = qmix, d = d, nu = nu)
stopifnot(all.equal(p.true_1, p.true_2, p.estim, tol = 1e-3, 
                    check.attributes = FALSE))

## Evaluate density function at 'x'
d.true_1 <- dgammamix(x, qmix = "inverse.gamma", d = d, df = nu)
d.true_2 <- df(x/d, df1 = d, df2 = nu)/d
d.est  <- dgammamix(x, qmix = qmix, d = d, nu = nu)
stopifnot(all.equal(d.true_1, d.true_2, d.est, tol = 5e-4, 
                    check.attributes = FALSE))

## Evaluate quantile function
u <- seq(from = 0.5, to = 0.9, by = 0.1)
q.true_1 <- qgammamix(u, qmix = "inverse.gamma", d = d, df = nu)
q.true_2 <- qf(u, df1 = d, df2 = nu) * d
q.est  <- qgammamix(u, qmix = qmix, d = d, nu = nu)
stopifnot(all.equal(q.true_1, q.true_2, q.est, tol = 5e-4, 
                    check.attributes = FALSE))

# }

Run the code above in your browser using DataCamp Workspace