Learn R Programming

extraDistr (version 1.8.1)

Laplace: Laplace distribution

Description

Density, distribution function, quantile function and random generation for the Laplace distribution.

Usage

dlaplace(x, mu = 0, sigma = 1, log = FALSE)
plaplace(q, mu = 0, sigma = 1, lower.tail = TRUE, log.p = FALSE)
qlaplace(p, mu = 0, sigma = 1, lower.tail = TRUE, log.p = FALSE)
rlaplace(n, mu = 0, sigma = 1)

Arguments

x, q
vector of quantiles.
mu, sigma
location and scale parameters. Scale must be positive.
log, log.p
logical; if TRUE, probabilities p are given as log(p).
lower.tail
logical; if TRUE (default), probabilities are $P[X \le x]$ otherwise, $P[X > x]$.
p
vector of probabilities.
n
number of observations. If length(n) > 1, the length is taken to be the number required.

Details

Probability density function $$ f(x) = \frac{1}{2\sigma} \exp\left(-\left|\frac{x-\mu}{\sigma}\right|\right) $$

Cumulative distribution function $$ F(x) = \left\{\begin{array}{ll} \frac{1}{2} \exp\left(\frac{x-\mu}{\sigma}\right) & x < \mu \\ 1 - \frac{1}{2} \exp\left(\frac{x-\mu}{\sigma}\right) & x \geq \mu \end{array}\right. $$

Quantile function $$ F^{-1}(p) = \left\{\begin{array}{ll} \mu + \sigma \log(2p) & p < 0.5 \\ \mu + \sigma \log(2(1-p)) & p \geq 0.5 \end{array}\right. $$

References

Krishnamoorthy, K. (2006). Handbook of Statistical Distributions with Applications. Chapman & Hall/CRC

Forbes, C., Evans, M. Hastings, N., & Peacock, B. (2011). Statistical Distributions. John Wiley & Sons.

Examples

Run this code

x <- rlaplace(1e5, 5, 16)
xx <- seq(-100, 100, by = 0.01)
hist(x, 100, freq = FALSE)
lines(xx, dlaplace(xx, 5, 16), col = "red")
hist(plaplace(x, 5, 16))
plot(ecdf(x))
lines(xx, plaplace(xx, 5, 16), col = "red", lwd = 2)

Run the code above in your browser using DataLab