Density function, distribution function, and expectile function and random generation for the distribution associated with the expectiles of a normal distribution.

denorm(x, mean = 0, sd = 1, log = FALSE)
penorm(q, mean = 0, sd = 1, lower.tail = TRUE, log.p = FALSE)
qenorm(p, mean = 0, sd = 1, Maxit.nr = 10, Tol.nr = 1.0e-6,
       lower.tail = TRUE, log.p = FALSE)
renorm(n, mean = 0, sd = 1)

Arguments

x, p, q

See deunif.

n, mean, sd, log

See rnorm.

lower.tail, log.p

Same meaning as in pnorm or qnorm.

Maxit.nr, Tol.nr

See deunif.

Details

General details are given in deunif including a note regarding the terminology used. Here, norm corresponds to the distribution of interest, \(F\), and enorm corresponds to \(G\). The addition of “e” is for the `other' distribution associated with the parent distribution. Thus denorm is for \(g\), penorm is for \(G\), qenorm is for the inverse of \(G\), renorm generates random variates from \(g\).

For qenorm the Newton-Raphson algorithm is used to solve for \(y\) satisfying \(p = G(y)\). Numerical problems may occur when values of p are very close to 0 or 1.

Value

denorm(x) gives the density function \(g(x)\). penorm(q) gives the distribution function \(G(q)\). qenorm(p) gives the expectile function: the value \(y\) such that \(G(y)=p\). renorm(n) gives \(n\) random variates from \(G\).

Author

T. W. Yee and Kai Huang

Examples

my.p <- 0.25; y <- rnorm(nn <- 1000)
(myexp <- qenorm(my.p))
#> [1] -0.4363266
sum(myexp - y[y <= myexp]) / sum(abs(myexp - y))  # Should be my.p
#> [1] 0.2698419

# Non-standard normal
mymean <- 1; mysd <- 2
yy <- rnorm(nn, mymean, mysd)
(myexp <- qenorm(my.p, mymean, mysd))
#> [1] 0.1273469
sum(myexp - yy[yy <= myexp]) / sum(abs(myexp - yy))  # Should be my.p
#> [1] 0.2218069
penorm(-Inf, mymean, mysd)      #  Should be 0
#> [1] 0
penorm( Inf, mymean, mysd)      #  Should be 1
#> [1] 1
penorm(mean(yy), mymean, mysd)  #  Should be 0.5
#> [1] 0.5309695
abs(qenorm(0.5, mymean, mysd) - mean(yy))  #  Should be 0
#> [1] 0.09896118
abs(penorm(myexp, mymean, mysd) - my.p)    #  Should be 0
#> [1] 2.775558e-17
integrate(f = denorm, lower = -Inf, upper = Inf,
          mymean, mysd)  #  Should be 1
#> 1 with absolute error < 0.00011

if (FALSE) { # \dontrun{
par(mfrow = c(2, 1))
yy <- seq(-3, 3, len = nn)
plot(yy, denorm(yy), type = "l", col="blue", xlab = "y", ylab = "g(y)",
     main = "g(y) for N(0,1); dotted green is f(y) = dnorm(y)")
lines(yy, dnorm(yy), col = "green", lty = "dotted", lwd = 2)  # 'original'

plot(yy, penorm(yy), type = "l", col = "blue", ylim = 0:1,
     xlab = "y", ylab = "G(y)", main = "G(y) for N(0,1)")
abline(v = 0, h = 0.5, col = "red", lty = "dashed")
lines(yy, pnorm(yy), col = "green", lty = "dotted", lwd = 2) } # }