Laplace {tsxtreme} | R Documentation |
The Laplace Distribution
Description
Density, distribution function, quantile function and random generation for the Laplace distribution with location parameter loc
and scale parameter scale
.
Usage
dlapl(x, loc = 0, scale = 1, log = FALSE)
plapl(q, loc = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
qlapl(p, loc = 0, scale = 1, lower.tail = TRUE, log.p = FALSE)
rlapl(n, loc = 0, scale = 1)
Arguments
x , q |
vector of quantiles. |
p |
vector of probabilities. |
n |
number of samples to generate. |
loc |
vector of location parameters. |
scale |
vector of scale parameters. These must be positive. |
lower.tail |
logical; if TRUE (default), probabilities are |
log , log.p |
logical; if TRUE, probabilities |
Details
If loc
or scale
are not specified, they assume the default values of 0 and 1 respectively.
The Laplace distribution has density
f(x) = \exp(- |x-\mu|/\sigma)/(2\sigma)
where \mu
is the location parameter and \sigma
is the scale parameter.
Value
dlapl
gives the density, plapl
gives the distribution function, qlapl
gives the quantile function, and rlapl
generates random deviates.
The length of the result is determined by n
in rlapl
, and is the maximum of the lengths of the numerical arguments for the other functions. Standard R
vector operations are to be assumed.
If sd
=0, the limit as sd
decreases to 0 is returned, i.e., a point mass at loc
. The case sd
<0 is an error and nothing is returned.
Warning
Some checks are done previous to standard evaluation, but vector computations have not yet been tested thoroughly! Typically vectors not having lengths multiple of each other return an error.
See Also
dexp for the exponential distribution which is the positive part of the Laplace distribution.
Examples
## evaluate the density function on a grid of values
x <- seq(from=-5, to=5, by=0.1)
fx <- dlapl(x, loc=1, scale=.5)
## generate random samples of a mixture of Laplace distributions
rnd <- rlapl(1000, loc=c(-5,-3,2), scale=0.5)
## an alternative:
rnd <- runif(1000)
rnd <- qlapl(rnd, loc=c(-5,-3,2), scale=0.5)
## integrate the Laplace density on [a,b]
a <- -1
b <- 7
integral <- plapl(b)-plapl(a)