Learn R Programming

LFM (version 0.3.4)

rlaplace: Generate Random Variables from the Laplace Distribution

Description

Generates random samples from the Laplace (double exponential) distribution with location parameter 0 and scale parameter 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.

Usage

rlaplace(n, b = 1)

Value

A numeric vector of length n containing random observations from the Laplace distribution.

Arguments

n

An integer specifying the number of observations to generate.

b

A positive numeric value specifying the scale parameter of the Laplace distribution. The default value is 1.

Details

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.

Examples

Run this code
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