% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/gamma.R
\name{gamma_mix}
\alias{gamma_mix}
\alias{dGammaMix}
\alias{pGammaMix}
\alias{rGammaMix}
\alias{qGammaMix}
\title{Gamma mixture distribution}
\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{
\item{x}{Numeric scalar giving the point at which the density is evaluated.}

\item{w}{Numeric vector of mixture weights of length \eqn{K}. The functions normalize \code{w}
internally when needed.}

\item{shape, scale}{Numeric vectors of length \eqn{K} giving Gamma shape and scale parameters.}

\item{log}{Logical; if \code{TRUE}, return the log-density.}

\item{q}{Numeric scalar giving the point at which the distribution function is evaluated.}

\item{lower.tail}{Logical; if \code{TRUE} (default), probabilities are \eqn{P(X \le q)}.}

\item{log.p}{Logical; if \code{TRUE}, probabilities are returned on the log scale.}

\item{n}{Integer giving the number of draws. The RNG implementation supports \code{n = 1}.}

\item{p}{Numeric scalar probability in \eqn{(0,1)} for the quantile function.}

\item{tol}{Numeric scalar tolerance passed to \code{stats::uniroot}.}

\item{maxiter}{Integer maximum number of iterations for \code{stats::uniroot}.}
}
\value{
Density/CDF/RNG functions return numeric scalars. \code{qGammaMix()} returns a numeric vector
with the same length as \code{p}.
}
\description{
Finite 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.
}
\details{
The mixture density is
\deqn{
f(x) = \sum_{k = 1}^K \tilde{w}_k f_{\Gamma}(x \mid \alpha_k, \theta_k),
\qquad x > 0,
}
with normalized weights \eqn{\tilde{w}_k}. For vectorized R usage, use \code{\link[=gamma_lowercase]{gamma_lowercase()}}.

Under the package parameterization, each component has density
\eqn{f_\Gamma(x \mid \alpha,\theta) = x^{\alpha-1}\exp(-x/\theta) /
\{\Gamma(\alpha)\theta^\alpha\}} on \eqn{x>0}. The mixture CDF is therefore
\deqn{
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, \code{qGammaMix()} obtains them numerically by inverting the mixture CDF.

The analytical mean is
\deqn{
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.
}
\section{Functions}{
\itemize{
\item \code{dGammaMix()}: Gamma mixture density

\item \code{pGammaMix()}: Gamma mixture distribution function

\item \code{rGammaMix()}: Gamma mixture random generation

\item \code{qGammaMix()}: Gamma mixture quantile function

}}
\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)
pGammaMix(2.0, w = w, scale = scale, shape = shape, lower.tail = 1, log.p = 0)
qGammaMix(0.50, w = w, scale = scale, shape = shape)
qGammaMix(0.95, w = w, scale = scale, shape = shape)
replicate(10, rGammaMix(1, w = w, scale = scale, shape = shape))
}
\seealso{
\code{\link[=gamma_mixgpd]{gamma_mixgpd()}}, \code{\link[=gamma_gpd]{gamma_gpd()}}, \code{\link[=gamma_lowercase]{gamma_lowercase()}}, \code{\link[=build_nimble_bundle]{build_nimble_bundle()}},
\code{\link[=kernel_support_table]{kernel_support_table()}}.

Other gamma kernel families: 
\code{\link{gamma_gpd}},
\code{\link{gamma_mixgpd}}
}
\concept{gamma kernel families}
