Skip to contents

The Laplace distribution, also known as the double exponential distribution, is a continuous probability distribution that is often used to model data with sharp peaks and heavy tails. It is parameterized by a location parameter \(\mu\) and a scale parameter \(b > 0\).

Usage

Laplace(mu = 0, sigma = 1)

dlaplace(x, mu, sigma, log = FALSE)

plaplace(q, mu, sigma, lower.tail = TRUE, log.p = FALSE)

qlaplace(p, mu, sigma, lower.tail = TRUE, log.p = FALSE)

rlaplace(n, mu, sigma)

# S4 method for class 'Laplace,numeric'
d(distr, x, log = FALSE)

# S4 method for class 'Laplace,numeric'
p(distr, q, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Laplace,numeric'
qn(distr, p, lower.tail = TRUE, log.p = FALSE)

# S4 method for class 'Laplace,numeric'
r(distr, n)

# S4 method for class 'Laplace'
mean(x)

# S4 method for class 'Laplace'
median(x)

# S4 method for class 'Laplace'
mode(x)

# S4 method for class 'Laplace'
var(x)

# S4 method for class 'Laplace'
sd(x)

# S4 method for class 'Laplace'
skew(x)

# S4 method for class 'Laplace'
kurt(x)

# S4 method for class 'Laplace'
entro(x)

# S4 method for class 'Laplace'
finf(x)

lllaplace(x, mu, sigma)

# S4 method for class 'Laplace,numeric'
ll(distr, x)

elaplace(x, type = "mle", ...)

# S4 method for class 'Laplace,numeric'
mle(distr, x, na.rm = FALSE)

# S4 method for class 'Laplace,numeric'
me(distr, x, na.rm = FALSE)

vlaplace(mu, sigma, type = "mle")

# S4 method for class 'Laplace'
avar_mle(distr)

# S4 method for class 'Laplace'
avar_me(distr)

Arguments

mu, sigma

numeric. The distribution parameters.

x

For the density function, x is a numeric vector of quantiles. For the moments functions, x is an object of class Laplace. For the log-likelihood and the estimation functions, x is the sample of observations.

log, log.p

logical. Should the logarithm of the probability be returned?

q

numeric. Vector of quantiles.

lower.tail

logical. If TRUE (default), probabilities are \(P(X \leq x)\), otherwise \(P(X > x)\).

p

numeric. Vector of probabilities.

n

number of observations. If length(n) > 1, the length is taken to be the number required.

distr

an object of class Laplace.

type

character, case ignored. The estimator type (mle or me).

...

extra arguments.

na.rm

logical. Should the NA values be removed?

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), p(), q(), r(), ll() functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr and x), they evaluate the aforementioned functions directly.

  • Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The moments() function returns a list with all the available methods.

  • Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.

  • Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.

Details

The probability density function (PDF) of the Laplace distribution is: $$ f(x; \mu, b) = \frac{1}{2b} \exp\left(-\frac{|x - \mu|}{b}\right) .$$

Examples

# -----------------------------------------------------
# Laplace Distribution Example
# -----------------------------------------------------

# Create the distribution
m <- 3 ; s <- 5
D <- Laplace(m, s)

# ------------------
# dpqr Functions
# ------------------

d(D, c(0.3, 2, 10)) # density function
#> [1] 0.05827483 0.08187308 0.02465970
p(D, c(0.3, 2, 10)) # distribution function
#> [1] 0.2913741 0.4093654 0.8767015
qn(D, c(0.4, 0.8)) # inverse distribution function
#> [1] 1.884282 7.581454
x <- r(D, 100) # random generator function

# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
#>   [1] 0.0255049011 0.0411834040 0.0462429105 0.0465894662 0.0415778861
#>   [6] 0.0568282165 0.0681336696 0.0926202989 0.0971288137 0.0039095983
#>  [11] 0.0122019484 0.0969991081 0.0364322510 0.0830665678 0.0050211357
#>  [16] 0.0500123026 0.0663597172 0.0716630141 0.0643986045 0.0450556273
#>  [21] 0.0664329885 0.0381311629 0.0798682086 0.0306833740 0.0112360638
#>  [26] 0.0111551880 0.0900457788 0.0189437140 0.0939240431 0.0843399497
#>  [31] 0.0154120931 0.0970061188 0.0414377373 0.0358009313 0.0643595795
#>  [36] 0.0426303986 0.0065052702 0.0041909611 0.0533525518 0.0426843733
#>  [41] 0.0154930544 0.0568691757 0.0656494853 0.0721713971 0.0102965415
#>  [46] 0.0772819964 0.0209844087 0.0292521537 0.0088187437 0.0619484873
#>  [51] 0.0692220467 0.0524187332 0.0413714186 0.0832574055 0.0315657900
#>  [56] 0.0940235447 0.0001178064 0.0857673395 0.0039464330 0.0395695716
#>  [61] 0.0661753114 0.0056440283 0.0464413826 0.0823896556 0.0868047631
#>  [66] 0.0410684344 0.0553180110 0.0412130329 0.0653067930 0.0272090108
#>  [71] 0.0768721399 0.0870514842 0.0151375011 0.0270272243 0.0156571540
#>  [76] 0.0542485144 0.0222024417 0.0543644589 0.0216261976 0.0109751517
#>  [81] 0.0123335455 0.0873977414 0.0317832441 0.0721013897 0.0445756467
#>  [86] 0.0492795968 0.0139500877 0.0492574904 0.0641078407 0.0913747413
#>  [91] 0.0609337283 0.0519808882 0.0925293788 0.0399075269 0.0768249620
#>  [96] 0.0303843228 0.0987945568 0.0730543641 0.0534809090 0.0792518551

# ------------------
# Moments
# ------------------

mean(D) # Expectation
#> [1] 3
median(D) # Median
#> [1] 3
mode(D) # Mode
#> [1] 3
var(D) # Variance
#> [1] 50
sd(D) # Standard Deviation
#> [1] 7.071068
skew(D) # Skewness
#> [1] 0
kurt(D) # Excess Kurtosis
#> [1] 6
entro(D) # Entropy
#> [1] 3.302585
finf(D) # Fisher Information Matrix
#>       mu sigma
#> mu     1   0.0
#> sigma  0   0.2

# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 3

# ------------------
# Point Estimation
# ------------------

elaplace(x, type = "mle")
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 
elaplace(x, type = "me")
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 

mle(D, x)
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 
me(D, x)
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 
e(D, x, type = "mle")
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 

mle("laplace", x) # the distr argument can be a character
#> $mu
#> [1] 2.954329
#> 
#> $sigma
#> [1] 4.948933
#> 

# ------------------
# Estimator Variance
# ------------------

vlaplace(m, s, type = "mle")
#>       mu sigma
#> mu     1     0
#> sigma  0     5
vlaplace(m, s, type = "me")
#>       mu sigma
#> mu     1     0
#> sigma  0     5

avar_mle(D)
#>       mu sigma
#> mu     1     0
#> sigma  0     5
avar_me(D)
#>       mu sigma
#> mu     1     0
#> sigma  0     5

v(D, type = "mle")
#>       mu sigma
#> mu     1     0
#> sigma  0     5