srlaplace | R Documentation |
The srlaplace()
function generates random samples from a Laplace Distribution using the STORS algorithm.
It employs an optimized proposal distribution around the mode and Inverse Transform (IT) method for the tails.
srlaplace(n = 1, mu = 0, b = 1, x = NULL)
srlaplace_custom(n = 1, x = NULL)
n |
Integer, length 1. Number of samples to draw. |
mu |
Numeric, location parameter. |
b |
Numeric, scale parameter. |
x |
(optional) Numeric vector of length |
The Laplace distribution has the probability density function (PDF):
f(x | \mu, b) = \frac{1}{2b} \exp\left(-\frac{|x - \mu|}{b}\right),
where:
\mu
is the location parameter (mean of the distribution).
b
is the scale parameter, which controls the spread of the distribution (b > 0
).
These two functions are for sampling using the STORS algorithm based on the proposal that has been constructed using srlaplace_optimize
.
By default, srlaplace()
samples from a standard Laplace Distribution (mu = 0
, b = 1
).
The proposal distribution is pre-optimized at package load time using srlaplace_optimize()
with
steps = 4091
, creating a scalable proposal centred around the mode.
If srlaplace()
is called with custom mu
or b
parameters, the samples are generated
from the standard Laplace Distribution, then scaled and location shifted accordingly.
A numeric vector of length n
containing samples from the Laplace Distribution with the specified
mu
and b
.
NOTE: When the x
parameter is specified, it is updated in-place with the simulation for performance reasons.
srlaplace_optimize
to optimize the custom or the scaled proposal.
# Generate 10 samples from the standard Laplace Distribution
samples <- srlaplace(10)
print(samples)
# Generate 10 samples using a pre-allocated vector
x <- numeric(10)
srlaplace(10, x = x)
print(x)
# Generate 10 samples from a Laplace Distribution with mu = 2 and b = 3
samples <- srlaplace(10, mu = 2, b = 3)
print(samples)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.