pnorMix {nor1mix} | R Documentation |
Compute cumulative probabilities or quantiles (the inverse) for a
normal mixture specified as norMix
object.
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 = 20)
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”. ....... |
l.interp |
positive integer for method = "interQpspline"
or "interpspline" , determining the number of values in each
“mu-interval”. |
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}] and
then 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)
.
a numeric vector of the same length as p
or q
, respectively.
Very first version (for length-1 p,q
) by
Erik Jørgensen Erik.Jorgensen@agrsci.dk.
dnorMix
for the density function.
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