qnorm.appr: Approximation to the inverse normal distribution function.

Description Usage Arguments Value Warning Note Author(s) Source Examples

Description

qnorm.ap* approximate the normal quantile function. They compute x such that P(x) = Prob(X <= x) = p.

Usage

1
2
3
  qnorm.app3(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
  qnorm.app4(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
  qnorm.ap16(p, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)

Arguments

p

vector of probabilities.

mean

vector of means.

sd

vector of standard deviations.

log.p

logical; if TRUE, probabilities p are given as log(p).

lower.tail

logical; if TRUE (default), probabilities are P(X <= x), otherwise, P(X > x).

Value

qnorm.ap* gives the quantile function for the different approximations.

Warning

If p <= 0 or p >= 1, then NA will be returned.

If p is very close to 1, a serious loss of significance may be incurred in forming c := 1 - p, resulting in p = 0. In this case c should be derived, if possible, directly (i.e. not by subtracting p from 1) and evaluate qnorm(p,...,lower.tail=B) as qnorm(c,...,lower.tail = (B==FALSE)).

Note

qnorm.ap16 is the approximation used in qnorm. The others have an absolute error < 10^{-3} and 10^{-4}.

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Source

qnorm.app3 and qnorm.app4: Abramowitz and Segun, Dover, 1968, formulae 26.2.22 and 26.2.23,

qnorm.ap16: Wichura, M. J., 1988. Algorithm AS 241: The Percentage Points of the Normal Distribution. Applied Statistics 37, 477-484.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
  prec <- function(x,y,z=y) max(abs((x-y)/z)) # relative precision
  x2 <- -0.6744897501960817; p2 <- 0.25
  x0 <- -3.090232306167814;  p0 <- 0.001
  xm <- -9.262340089798408;  pm <- 1.0e-20
  x  <- c((-100:0)/10,x2,x0,xm)
  p  <- pnorm(x)
  x3 <- qnorm.app3(p)
  x4 <- qnorm.app4(p)
  x1 <- qnorm.ap16(p)
# Check relative precision of approximations
  prec(x,x3,1)  # 0.002817442
  prec(x,x4,1)  # 0.0004435874
  prec(x,x1,1)  # 0.1571311 why so bad ?
  prec(x,qnorm(p),1)  # 1.776357e-15
# Special values
  prec(qnorm.app3(p2),x2)  # 0.004089976
  prec(qnorm.app3(p0),x0)  # 0.0007736497
  prec(qnorm.app3(pm),xm)  # 7.29796e-06
  prec(qnorm.app4(p2),x2)  # 0.0004456853
  prec(qnorm.app4(p0),x0)  # 9.381806e-05
  prec(qnorm.app4(pm),xm)  # 4.151165e-05
  prec(qnorm.ap16(p2),x2)  # 0
  prec(qnorm.ap16(p0),x0)  # 2.874148e-16
  prec(qnorm.ap16(pm),xm)  # 0.01211545
  

cwhmisc documentation built on May 1, 2019, 7:55 p.m.