| Exponential {stats} | R Documentation |
The Exponential Distribution
Description
Density, distribution function, quantile function and random
generation for the exponential distribution with rate rate
(i.e., mean 1/rate).
Usage
dexp(x, rate = 1, log = FALSE)
pexp(q, rate = 1, lower.tail = TRUE, log.p = FALSE)
qexp(p, rate = 1, lower.tail = TRUE, log.p = FALSE)
rexp(n, rate = 1)
Arguments
x, q |
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. If |
rate |
vector of rates. |
log, log.p |
logical; if |
lower.tail |
logical; if |
Details
If rate is not specified, it assumes the default value of
1.
The exponential distribution with rate \lambda has density
f(x) = \lambda {e}^{- \lambda x}
for x \ge 0.
Value
dexp gives the density,
pexp is the cumulative distribution function, and
qexp is the quantile function of the exponential distribution.
rexp generates random deviates.
The length of the result is determined by n for
rexp, and is the maximum of the lengths of the
numerical arguments for the other functions.
The numerical arguments other than n are recycled to the
length of the result. Only the first elements of the logical
arguments are used.
Note
The cumulative hazard H(t) = - \log(1 - F(t))
is -pexp(t, r, lower = FALSE, log = TRUE).
Source
dexp, pexp and qexp are all calculated
from numerically stable versions of the definitions.
rexp uses Ahrens and Dieter (1972).
References
Ahrens JH, Dieter U (1972). “Computer Methods for Sampling from the Exponential and Normal Distributions.” Communications of the ACM, 15(10), 873–882. doi:10.1145/355604.361593.
Becker RA, Chambers JM, Wilks AR (1988). The New S Language. Chapman and Hall/CRC, London.
Johnson NL, Kotz S, Balakrishnan N (1994).
Continuous Univariate Distributions, volume 1.
Wiley, New York.
ISBN 978-0-471-58495-7.
Chapter 19.
See Also
exp for the exponential function.
Distributions for other standard distributions, including
dgamma for the gamma distribution and
dweibull for the Weibull distribution, both of which
generalize the exponential.
Examples
dexp(1) - exp(-1) #-> 0
## a fast way to generate *sorted* U[0,1] random numbers:
rsunif <- function(n) { n1 <- n+1
cE <- cumsum(rexp(n1)); cE[seq_len(n)]/cE[n1] }
plot(rsunif(1000), ylim=0:1, pch=".")
abline(0,1/(1000+1), col=adjustcolor(1, 0.5))