powered by
Generates random samples from the Laplace (double exponential) distribution with location parameter 0 and scale parameter b.
b
The probability density function is
$$ f(x)=\frac{1}{2b}\exp\left(-\frac{|x|}{b}\right), $$
where \(b>0\) is the scale parameter.
Random numbers are generated using the inverse transform method.
rlaplace(n, b = 1)
A numeric vector of length n containing random observations from the Laplace distribution.
n
An integer specifying the number of observations to generate.
A positive numeric value specifying the scale parameter of the Laplace distribution. The default value is 1.
1
If \(X \sim Laplace(0,b)\), then
$$ E(X)=0, $$
and
$$ Var(X)=2b^2. $$
This function is used internally by the Laplace Factor Model (LFM) package for generating Laplace-distributed error terms.
set.seed(123) x <- rlaplace(1000) mean(x) var(x) hist(x, breaks = 30, main = "Laplace Random Sample", xlab = "x")
Run the code above in your browser using DataLab