% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/normal.R
\name{normal_mix}
\alias{normal_mix}
\alias{dNormMix}
\alias{pNormMix}
\alias{rNormMix}
\alias{qNormMix}
\title{Normal mixture distribution}
\usage{
dNormMix(x, w, mean, sd, log = 0)

pNormMix(q, w, mean, sd, lower.tail = 1, log.p = 0)

rNormMix(n, w, mean, sd)

qNormMix(
  p,
  w,
  mean,
  sd,
  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{mean, sd}{Numeric vectors of length \eqn{K} giving component means and 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{qNormMix()} returns a numeric vector
with the same length as \code{p}.
}
\description{
Finite mixture of normal components for real-valued bulk modeling. This topic provides the
scalar mixture density, CDF, RNG, and quantile functions used by the bulk-only normal kernel in
the package registry.
}
\details{
With weights \eqn{w_k}, means \eqn{\mu_k}, and standard deviations \eqn{\sigma_k}, the mixture
density is
\deqn{
f(x) = \sum_{k = 1}^K \tilde{w}_k \phi(x \mid \mu_k, \sigma_k^2),
}
where \eqn{\tilde{w}_k = w_k / \sum_j w_j}. These uppercase functions are scalar
NIMBLE-compatible building blocks. For vectorized R usage, use \code{\link[=normal_lowercase]{normal_lowercase()}}.

If \eqn{F_k} denotes the \eqn{k}-th component CDF, then the mixture distribution function is
\deqn{
F(x) = \sum_{k=1}^K \tilde{w}_k F_k(x)
= \sum_{k=1}^K \tilde{w}_k \Phi\left(\frac{x-\mu_k}{\sigma_k}\right).
}
Random generation first draws a component index with probability \eqn{\tilde{w}_k} and then
generates from the corresponding normal law. The quantile function has no closed form for a
general finite mixture, so \code{qNormMix()} solves \eqn{F(x)=p} numerically by bracketing the
root and applying \code{stats::uniroot()}.

The mixture mean is
\deqn{
E(X) = \sum_{k=1}^K \tilde{w}_k \mu_k,
}
which is the analytical mean used by the package when a normal-mixture draw contributes to a
posterior predictive mean calculation.
}
\section{Functions}{
\itemize{
\item \code{dNormMix()}: Normal mixture density

\item \code{pNormMix()}: Normal mixture distribution function

\item \code{rNormMix()}: Normal mixture random generation

\item \code{qNormMix()}: Normal mixture quantile function

}}
\examples{
w <- c(0.60, 0.25, 0.15)
mean <- c(-1, 0.5, 2.0)
sd <- c(1.0, 0.7, 1.3)

dNormMix(0.5, w = w, mean = mean, sd = sd, log = FALSE)
pNormMix(0.5, w = w, mean = mean, sd = sd,
        lower.tail = TRUE, log.p = FALSE)
qNormMix(0.50, w = w, mean = mean, sd = sd)
qNormMix(0.95, w = w, mean = mean, sd = sd)
replicate(10, rNormMix(1, w = w, mean = mean, sd = sd))
}
\seealso{
\code{\link[=normal_mixgpd]{normal_mixgpd()}}, \code{\link[=normal_gpd]{normal_gpd()}}, \code{\link[=normal_lowercase]{normal_lowercase()}}, \code{\link[=build_nimble_bundle]{build_nimble_bundle()}},
\code{\link[=kernel_support_table]{kernel_support_table()}}.

Other normal kernel families: 
\code{\link{normal_gpd}},
\code{\link{normal_mixgpd}}
}
\concept{normal kernel families}
