% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/lognormal.R
\name{lognormal_mixgpd}
\alias{lognormal_mixgpd}
\alias{dLognormalMixGpd}
\alias{pLognormalMixGpd}
\alias{rLognormalMixGpd}
\alias{qLognormalMixGpd}
\title{Lognormal mixture with a GPD tail}
\usage{
dLognormalMixGpd(
  x,
  w,
  meanlog,
  sdlog,
  threshold,
  tail_scale,
  tail_shape,
  log = 0
)

pLognormalMixGpd(
  q,
  w,
  meanlog,
  sdlog,
  threshold,
  tail_scale,
  tail_shape,
  lower.tail = 1,
  log.p = 0
)

rLognormalMixGpd(n, w, meanlog, sdlog, threshold, tail_scale, tail_shape)

qLognormalMixGpd(
  p,
  w,
  meanlog,
  sdlog,
  threshold,
  tail_scale,
  tail_shape,
  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}.}

\item{meanlog, sdlog}{Numeric vectors of length \eqn{K} giving component log-means and log-standard deviations.}

\item{threshold}{Numeric scalar threshold at which the GPD tail is attached.}

\item{tail_scale}{Numeric scalar GPD scale parameter; must be positive.}

\item{tail_shape}{Numeric scalar GPD shape parameter.}

\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} in quantile inversion.}

\item{maxiter}{Integer maximum number of iterations for \code{stats::uniroot}.}
}
\value{
Spliced density/CDF/RNG functions return numeric scalars.
\code{qLognormalMixGpd()} returns a numeric vector with the same length as \code{p}.
}
\description{
Spliced bulk-tail family formed by attaching a generalized Pareto tail to a lognormal mixture
bulk.
Let \eqn{F_{mix}} be the Lognormal mixture CDF. The spliced CDF is
\eqn{F(x)=F_{mix}(x)} for \eqn{x<threshold} and
\eqn{F(x)=F_{mix}(threshold) + \{1-F_{mix}(threshold)\}G(x)} for \eqn{x\ge threshold}, where \eqn{G}
is the GPD CDF for exceedances above \code{threshold}.
}
\details{
The density, CDF, and RNG are implemented as \code{nimbleFunction}s. The quantile is an R function:
it uses numerical inversion in the bulk region and the closed-form GPD quantile in the tail.

Let \eqn{F_{mix}} be the lognormal-mixture CDF and let \eqn{u} denote the threshold. The splice
uses the bulk law below \eqn{u} and attaches a GPD to the residual survival mass above
\eqn{u}. The density therefore becomes
\deqn{
f(x) =
\left\{
\begin{array}{ll}
f_{mix}(x), & x < u, \\
\{1-F_{mix}(u)\} g_{GPD}(x \mid u,\sigma_u,\xi), & x \ge u.
\end{array}
\right.
}
The quantile is computed piecewise: bulk quantiles are obtained numerically from the mixture CDF,
whereas tail quantiles use the closed-form GPD inverse after rescaling the upper-tail
probability.
}
\section{Functions}{
\itemize{
\item \code{dLognormalMixGpd()}: Lognormal mixture + GPD tail density

\item \code{pLognormalMixGpd()}: Lognormal mixture + GPD tail distribution function

\item \code{rLognormalMixGpd()}: Lognormal mixture + GPD tail random generation

\item \code{qLognormalMixGpd()}: Lognormal mixture + GPD tail 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)
threshold <- 3
tail_scale <- 0.9
tail_shape <- 0.2

dLognormalMixGpd(4.0, w = w, meanlog = meanlog, sdlog = sdlog,
                threshold = threshold, tail_scale = tail_scale,
                tail_shape = tail_shape, log = FALSE)
pLognormalMixGpd(4.0, w = w, meanlog = meanlog, sdlog = sdlog,
                threshold = threshold, tail_scale = tail_scale,
                tail_shape = tail_shape, lower.tail = TRUE, log.p = FALSE)
qLognormalMixGpd(0.50, w = w, meanlog = meanlog, sdlog = sdlog,
                threshold = threshold, tail_scale = tail_scale,
                tail_shape = tail_shape)
qLognormalMixGpd(0.95, w = w, meanlog = meanlog, sdlog = sdlog,
                threshold = threshold, tail_scale = tail_scale,
                tail_shape = tail_shape)
replicate(10, rLognormalMixGpd(1, w = w, meanlog = meanlog, sdlog = sdlog,
                              threshold = threshold,
                              tail_scale = tail_scale,
                              tail_shape = tail_shape))
}
\seealso{
\code{\link[=lognormal_mix]{lognormal_mix()}}, \code{\link[=lognormal_gpd]{lognormal_gpd()}}, \code{\link[=gpd]{gpd()}}, \code{\link[=lognormal_lowercase]{lognormal_lowercase()}}, \code{\link[=dpmgpd]{dpmgpd()}}.

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