% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/laplace.R
\name{laplace_mix}
\alias{laplace_mix}
\alias{dLaplaceMix}
\alias{pLaplaceMix}
\alias{rLaplaceMix}
\alias{qLaplaceMix}
\title{Laplace (double exponential) mixture distribution}
\usage{
dLaplaceMix(x, w, location, scale, log = 0)

pLaplaceMix(q, w, location, scale, lower.tail = 1, log.p = 0)

rLaplaceMix(n, w, location, scale)

qLaplaceMix(
  p,
  w,
  location,
  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{location}{Numeric vector of length \eqn{K} giving component locations.}

\item{scale}{Numeric vector of length \eqn{K} giving component scales.}

\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 iterations for \code{stats::uniroot}.}
}
\value{
Density/CDF/RNG functions return numeric scalars. \code{qLaplaceMix()} returns a numeric
vector with the same length as \code{p}.
}
\description{
Finite mixture of Laplace components for real-valued bulk modeling. The scalar functions in this
topic are the NIMBLE-compatible building blocks for Laplace-based kernels.
}
\details{
The mixture density is
\deqn{
f(x) = \sum_{k = 1}^K \tilde{w}_k f_{Lap}(x \mid \mu_k, b_k),
}
with normalized weights \eqn{\tilde{w}_k}. For vectorized R usage, use \code{\link[=laplace_lowercase]{laplace_lowercase()}}.

Each component is a Laplace law with density
\eqn{f(x \mid \mu,b) = (2b)^{-1}\exp\{-|x-\mu|/b\}}. The mixture CDF is the corresponding
weighted average of component CDFs, and random generation selects a component first and then
samples from that component. As with the other finite mixtures in the package, the quantile has
no closed form and is therefore obtained numerically.

The analytical mean of the mixture is simply
\deqn{
E(X) = \sum_{k=1}^K \tilde{w}_k \mu_k.
}
That is the formula used in downstream predictive mean calculations for Laplace-based fits.
}
\section{Functions}{
\itemize{
\item \code{dLaplaceMix()}: Laplace mixture density

\item \code{pLaplaceMix()}: Laplace mixture distribution function

\item \code{rLaplaceMix()}: Laplace mixture random generation

\item \code{qLaplaceMix()}: Laplace mixture quantile function

}}
\examples{
w <- c(0.50, 0.30, 0.20)
location <- c(-1, 0.5, 2.0)
scale <- c(1.0, 0.7, 1.4)

dLaplaceMix(0.8, w = w, location = location, scale = scale, log = FALSE)
pLaplaceMix(0.8, w = w, location = location, scale = scale,
           lower.tail = TRUE, log.p = FALSE)
qLaplaceMix(0.50, w = w, location = location, scale = scale)
qLaplaceMix(0.95, w = w, location = location, scale = scale)
replicate(10, rLaplaceMix(1, w = w, location = location, scale = scale))
}
\seealso{
\code{\link[=laplace_MixGpd]{laplace_MixGpd()}}, \code{\link[=laplace_gpd]{laplace_gpd()}}, \code{\link[=laplace_lowercase]{laplace_lowercase()}},
\code{\link[=build_nimble_bundle]{build_nimble_bundle()}}, \code{\link[=kernel_support_table]{kernel_support_table()}}.

Other laplace kernel families: 
\code{\link{laplace_MixGpd}},
\code{\link{laplace_gpd}}
}
\concept{laplace kernel families}
