densities: The Laplace Distribution

Description Usage Arguments Details Value Warning See Also Examples

Description

Density, distribution function, quantile function and random generation for the Laplace distribution with location parameter loc and scale parameter scale.

Usage

1
2
3
4
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 Pr(X≤ x), otherwise Pr(X>x).

log,log.p

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

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-μ|/σ)/(2σ)

where μ is the location parameter and σ 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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)

tsxtreme documentation built on April 24, 2021, 1:07 a.m.