# pnorMix: Normal Mixture Cumulative Distribution and Quantiles In nor1mix: Normal (1-d) Mixture Models (S3 Classes and Methods)

## Description

Compute cumulative probabilities or quantiles (the inverse) for a normal mixture specified as `norMix` object.

## Usage

 ```1 2 3 4 5 6``` ```pnorMix(q, obj, lower.tail = TRUE, log.p = FALSE) qnorMix(p, obj, lower.tail = TRUE, log.p = FALSE, tol = .Machine\$double.eps^0.25, maxiter = 1000, traceRootsearch = 0, method = c("interpQspline", "interpspline", "eachRoot", "root2"), l.interp = pmax(1, pmin(20, 1000 / m)), n.mu.interp = 100) ```

## Arguments

 `obj` an object of class `norMix`. `p` numeric vector of probabilities. Note that for all `method`s but `"eachRoot"`, `qnorMix(p, *)` works with the full vector `p`, typically using (inverse) interpolation approaches; consequently the result is very slightly dependent on `p` as a whole. `q` numeric vector of quantiles

.

 `lower.tail` logical; if TRUE (default), probabilities are P[X <= x], otherwise, P[X > x]. `log.p` logical; if TRUE, probabilities p are given as log(p). `tol, maxiter` tolerance and maximal number of iterations for the root search algorithm, see `method` below and `uniroot`. `traceRootsearch` logical or integer in \{0,1,2,3\}, determining the amount of information printed during root search. `method` a string specifying which algorithm is used for the “root search”. Originally, the only method was a variation of `"eachRoot"`, which is the default now when only very few quantiles are sought. For large `m.norMix()`, the default is set to `"root2"`, currently. `l.interp` positive integer for `method = "interQpspline"` or `"interpspline"`, determining the number of values in each “mu-interval”. `n.mu.interp` positive integer for `method = "interQpspline"` or `"interpspline"`, determining the (maximal) number of mu-values to be used as knots for inverse interpolation.

## Details

Whereas the distribution function `pnorMix` is the trivial sum of weighted normal probabilities (`pnorm`), its inverse, `qnorMix` is computed numerically: For each `p` we search for `q` such that `pnorMix(obj, q) == p`, i.e., f(q) = 0 for `f(q) := pnorMix(obj, q) - p`. This is a root finding problem which can be solved by `uniroot(f, lower,upper,*)`. If `length(p) <= 2` or `method = "eachRoot"`, this happens one for one for the sorted p's. Otherwise, we start by doing this for the outermost non-trivial (0 < p < 1) values of p.

For `method = "interQpspline"` or `"interpspline"`, we now compute `p. <- pnorMix(q., obj)` for values `q.` which are a grid of length `l.interp` in each interval [q_j,q_{j+1}], where q_j are the “X-extremes” plus (a sub sequence of length `n.mu.interp` of) theordered `mu[j]`'s. Then, we use montone inverse interpolation (`splinefun(q., p., method="monoH.FC")`) plus a few (maximally `maxiter`, typically one!) Newton steps. The default, `"interQpspline"`, additionally logit-transforms the `p.` values to make the interpolation more linear. This method is faster, particularly for large `length(p)`.

## Value

a numeric vector of the same length as `p` or `q`, respectively.

## Author(s)

Very first version (for length-1 `p,q`) by Erik J<c3><b8>rgensen [email protected].

`dnorMix` for the density function.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12``` ```MW.nm3 # the "strange skew" one plot(MW.nm3) ## now the cumlative : x <- seq(-4,4, length=1001) plot(x, pnorMix(x, MW.nm3), type="l", col=2) ## and some of its inverse : pp <- seq(.1, .9, by=.1) plot(qnorMix(pp, MW.nm3), pp) ## The "true" median of a normal mixture: median.norMix <- function(x) qnorMix(1/2, x) median.norMix(MW.nm3) ## -2.32 ```