% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lognormal.R
\name{lognormal_mix}
\alias{lognormal_mix}
\alias{dLognormalMix}
\alias{pLognormalMix}
\alias{rLognormalMix}
\alias{qLognormalMix}
\title{Lognormal mixture distribution}
\usage{
dLognormalMix(x, w, meanlog, sdlog, log = 0)

pLognormalMix(q, w, meanlog, sdlog, lower.tail = 1, log.p = 0)

rLognormalMix(n, w, meanlog, sdlog)

qLognormalMix(
  p,
  w,
  meanlog,
  sdlog,
  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{meanlog, sdlog}{Numeric vectors of length \eqn{K} giving component log-means and log-standard deviations.}

\item{log}{Integer flag \code{0/1}; if \code{1}, return the log-density.}

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

\item{lower.tail}{Integer flag \code{0/1}; if \code{1} (default), probabilities are \eqn{P(X \le q)}.}

\item{log.p}{Integer flag \code{0/1}; if \code{1}, 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{qLognormalMix()} returns a numeric
vector with the same length as \code{p}.
}
\description{
Finite mixture of lognormal components for positive-support bulk modeling. The scalar functions
in this topic are the NIMBLE-compatible building blocks for the lognormal bulk kernel family.
}
\details{
The mixture density is
\deqn{
f(x) = \sum_{k = 1}^K \tilde{w}_k f_{LN}(x \mid \mu_k, \sigma_k),
\qquad x > 0,
}
with normalized weights \eqn{\tilde{w}_k}. For vectorized R usage, use \code{\link[=lognormal_lowercase]{lognormal_lowercase()}}.

Each component satisfies \eqn{\log X_k \sim N(\mu_k,\sigma_k^2)}, so the mixture CDF is
\deqn{
F(x) = \sum_{k=1}^K \tilde{w}_k
\Phi\left(\frac{\log x-\mu_k}{\sigma_k}\right), \qquad x>0.
}
Random generation proceeds by drawing a component index with probability \eqn{\tilde{w}_k} and
then sampling from the corresponding lognormal law. Because a finite mixture of lognormals does
not admit a closed-form inverse CDF, \code{qLognormalMix()} computes quantiles by numerical
inversion.

The analytical mixture mean is
\deqn{
E(X) = \sum_{k=1}^K \tilde{w}_k \exp(\mu_k + \sigma_k^2/2),
}
which is the expression used by the package whenever an ordinary predictive mean exists.
}
\section{Functions}{
\itemize{
\item \code{dLognormalMix()}: Lognormal mixture density

\item \code{pLognormalMix()}: Lognormal mixture distribution function

\item \code{rLognormalMix()}: Lognormal mixture random generation

\item \code{qLognormalMix()}: Lognormal mixture quantile function

}}
\examples{
w <- c(0.60, 0.25, 0.15)
meanlog <- c(-0.2, 0.6, 1.2)
sdlog <- c(0.4, 0.3, 0.5)

dLognormalMix(2.0, w = w, meanlog = meanlog, sdlog = sdlog, log = FALSE)
pLognormalMix(2.0, w = w, meanlog = meanlog, sdlog = sdlog,
             lower.tail = TRUE, log.p = FALSE)
qLognormalMix(0.50, w = w, meanlog = meanlog, sdlog = sdlog)
qLognormalMix(0.95, w = w, meanlog = meanlog, sdlog = sdlog)
replicate(10, rLognormalMix(1, w = w, meanlog = meanlog, sdlog = sdlog))
}
\seealso{
\code{\link[=lognormal_mixgpd]{lognormal_mixgpd()}}, \code{\link[=lognormal_gpd]{lognormal_gpd()}}, \code{\link[=lognormal_lowercase]{lognormal_lowercase()}},
\code{\link[=build_nimble_bundle]{build_nimble_bundle()}}, \code{\link[=kernel_support_table]{kernel_support_table()}}.

Other lognormal kernel families: 
\code{\link{lognormal_gpd}},
\code{\link{lognormal_mixgpd}}
}
\concept{lognormal kernel families}
