Gamma mixture distribution
gamma_mix.RdFinite mixture of gamma components for positive-support bulk modeling. The scalar functions in this topic are the compiled building blocks behind the gamma bulk kernel family.
Usage
dGammaMix(x, w, shape, scale, log = 0)
pGammaMix(q, w, shape, scale, lower.tail = 1, log.p = 0)
rGammaMix(n, w, shape, scale)
qGammaMix(
p,
w,
shape,
scale,
lower.tail = TRUE,
log.p = FALSE,
tol = 1e-10,
maxiter = 200
)Arguments
- x
Numeric scalar giving the point at which the density is evaluated.
- w
Numeric vector of mixture weights of length \(K\). The functions normalize
winternally when needed.- shape, scale
Numeric vectors of length \(K\) giving Gamma shape and scale parameters.
- log
Logical; if
TRUE, return the log-density.- q
Numeric scalar giving the point at which the distribution function is evaluated.
- lower.tail
Logical; if
TRUE(default), probabilities are \(P(X \le q)\).- log.p
Logical; if
TRUE, probabilities are returned on the log scale.- n
Integer giving the number of draws. The RNG implementation supports
n = 1.- p
Numeric scalar probability in \((0,1)\) for the quantile function.
- tol
Numeric scalar tolerance passed to
stats::uniroot.- maxiter
Integer maximum number of iterations for
stats::uniroot.
Value
Density/CDF/RNG functions return numeric scalars. qGammaMix() returns a numeric vector
with the same length as p.
Details
The mixture density is
$$
f(x) = \sum_{k = 1}^K \tilde{w}_k f_{\Gamma}(x \mid \alpha_k, \theta_k),
\qquad x > 0,
$$
with normalized weights \(\tilde{w}_k\). For vectorized R usage, use gamma_lowercase().
Under the package parameterization, each component has density
\(f_\Gamma(x \mid \alpha,\theta) = x^{\alpha-1}\exp(-x/\theta) /
\{\Gamma(\alpha)\theta^\alpha\}\) on \(x>0\). The mixture CDF is therefore
$$
F(x) = \sum_{k=1}^K \tilde{w}_k F_\Gamma(x \mid \alpha_k,\theta_k).
$$
Random generation first selects a component according to the normalized mixture weights and then
draws from the corresponding gamma distribution. Since finite gamma mixtures do not have closed
form quantiles, qGammaMix() obtains them numerically by inverting the mixture CDF.
The analytical mean is $$ E(X) = \sum_{k=1}^K \tilde{w}_k \alpha_k \theta_k. $$ This expression is reused in posterior predictive mean calculations for gamma-based fits.
Functions
dGammaMix(): Gamma mixture densitypGammaMix(): Gamma mixture distribution functionrGammaMix(): Gamma mixture random generationqGammaMix(): Gamma mixture quantile function
See also
gamma_mixgpd(), gamma_gpd(), gamma_lowercase(), build_nimble_bundle(),
kernel_support_table().
Other gamma kernel families:
gamma_gpd,
gamma_mixgpd
Examples
w <- c(0.55, 0.30, 0.15)
scale <- c(1.0, 2.5, 5.0)
shape <- c(2, 4, 6)
dGammaMix(2.0, w = w, scale = scale, shape = shape, log = 0)
#> [1] 0.1534717
pGammaMix(2.0, w = w, scale = scale, shape = shape, lower.tail = 1, log.p = 0)
#> [1] 0.3294213
qGammaMix(0.50, w = w, scale = scale, shape = shape)
#> [1] 3.623739
qGammaMix(0.95, w = w, scale = scale, shape = shape)
#> [1] 33.81667
replicate(10, rGammaMix(1, w = w, scale = scale, shape = shape))
#> [1] 7.4874491 7.6825718 58.5380719 0.7576791 10.4751979 21.6543832
#> [7] 0.4246413 9.1363824 1.1727450 17.8997664