% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/normal.R
\name{normal_mixgpd}
\alias{normal_mixgpd}
\alias{dNormMixGpd}
\alias{pNormMixGpd}
\alias{rNormMixGpd}
\alias{qNormMixGpd}
\title{Normal mixture with a GPD tail}
\usage{
dNormMixGpd(x, w, mean, sd, threshold, tail_scale, tail_shape, log = 0)

pNormMixGpd(
  q,
  w,
  mean,
  sd,
  threshold,
  tail_scale,
  tail_shape,
  lower.tail = 1,
  log.p = 0
)

rNormMixGpd(n, w, mean, sd, threshold, tail_scale, tail_shape)

qNormMixGpd(
  p,
  w,
  mean,
  sd,
  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{mean, sd}{Numeric vectors of length \eqn{K} giving component means and 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}.}

\item{maxiter}{Integer maximum number of iterations for \code{stats::uniroot}.}
}
\value{
Spliced density/CDF/RNG functions return numeric scalars. \code{qNormMixGpd()} 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 normal mixture bulk.
This matches the structure used by the package's normal \code{mixgpd} kernels.
}
\details{
If \eqn{F_{mix}} denotes the normal-mixture CDF, the spliced CDF is
\deqn{
F(x) =
\left\{
\begin{array}{ll}
F_{mix}(x), & x < u, \\
F_{mix}(u) + \{1 - F_{mix}(u)\} G(x), & x \ge u,
\end{array}
\right.
}
where \code{threshold = u} and \eqn{G} is the GPD CDF.

The construction keeps the normal mixture unchanged below the threshold \eqn{u} and replaces the
upper tail by a generalized Pareto exceedance model. Writing \eqn{F_{mix}(u)=p_u}, the spliced
density is
\deqn{
f(x) =
\left\{
\begin{array}{ll}
f_{mix}(x), & x < u, \\
\{1-p_u\} g_{GPD}(x \mid u,\sigma_u,\xi), & x \ge u.
\end{array}
\right.
}
This formulation preserves total probability because the GPD is attached only to the residual
survival mass above the bulk threshold.

The quantile is piecewise. If \eqn{p \le p_u}, \code{qNormMixGpd()} inverts the bulk mixture
CDF; otherwise it rescales the tail probability to \eqn{(p-p_u)/(1-p_u)} and applies the
closed-form GPD quantile. That same piecewise logic is what the fitted-model prediction code
uses draw by draw.
}
\section{Functions}{
\itemize{
\item \code{dNormMixGpd()}: Normal mixture + GPD tail density

\item \code{pNormMixGpd()}: Normal mixture + GPD tail distribution function

\item \code{rNormMixGpd()}: Normal mixture + GPD tail random generation

\item \code{qNormMixGpd()}: Normal mixture + GPD tail 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)
threshold <- 2
tail_scale <- 1.0
tail_shape <- 0.2

dNormMixGpd(3.0, w, mean, sd, threshold, tail_scale, tail_shape, log = FALSE)
pNormMixGpd(3.0, w, mean, sd, threshold, tail_scale, tail_shape,
           lower.tail = TRUE, log.p = FALSE)
qNormMixGpd(0.50, w, mean, sd, threshold, tail_scale, tail_shape)
qNormMixGpd(0.95, w, mean, sd, threshold, tail_scale, tail_shape)
replicate(10, rNormMixGpd(1, w, mean, sd, threshold, tail_scale, tail_shape))
}
\seealso{
\code{\link[=normal_mix]{normal_mix()}}, \code{\link[=normal_gpd]{normal_gpd()}}, \code{\link[=gpd]{gpd()}}, \code{\link[=normal_lowercase]{normal_lowercase()}}, \code{\link[=dpmgpd]{dpmgpd()}}.

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