
Sampling from Exponential Distribution
srexp.Rd
The srexp()
function generates random samples from a Exponential Distribution using the STORS algorithm.
It employs an optimized proposal distribution around the mode and Inverse Transform (IT) method for the tails.
Value
A numeric vector of length n
containing samples from the Exponential Distribution with the specified
rate
.
NOTE: When the x
parameter is specified, it is updated in-place with the simulation for performance reasons.
Details
The Exponential distribution has the probability density function (PDF): \(f(x | \lambda) = \lambda \exp(-\lambda x), \quad x \geq 0,\) where:
- \(\lambda\)
is the rate parameter (\(\lambda > 0\)), which determines the rate of decay of the distribution.
The Exponential distribution is commonly used to model the time between independent events that occur at a constant average rate.
These two functions are for sampling using the STORS algorithm based on the proposal that has been constructed using srexp_optimize
.
By default, srexp()
samples from a standard Exponential Distribution rate = 1
.
The proposal distribution is pre-optimized at package load time using srexp_optimize()
with
steps = 4091
, creating a scalable proposal centred around the mode.
If srexp()
is called with custom rate
parameter, the samples are generated
from the standard Exponential Distribution, then scaled accordingly.
See also
srexp_optimize
to optimize the custom or the scaled proposal.
Examples
# Generate 10 samples from the standard Exponential Distribution
samples <- srexp(10)
print(samples)
#> [1] 0.346937156 1.552504781 0.463645529 1.549163657 0.004035847 0.045445347
#> [7] 1.942422858 1.105998132 0.589538535 0.543863633
# Generate 10 samples using a pre-allocated vector
x <- numeric(10)
srexp(10, x = x)
#> [1] 1.6073773 0.4791929 0.8108571 0.9130973 3.1566473 2.7938740 0.1416178
#> [8] 0.5033368 1.1398343 1.1074866
print(x)
#> [1] 1.6073773 0.4791929 0.8108571 0.9130973 3.1566473 2.7938740 0.1416178
#> [8] 0.5033368 1.1398343 1.1074866
# Generate 10 samples from a Exponential Distribution with rate = 4
samples <- srexp(10, rate = 4)
print(samples)
#> [1] 1.477180e-01 4.082474e-01 7.058136e-01 4.844079e-02 7.008243e-01
#> [6] 1.727140e-01 6.535919e-02 2.290851e-02 9.057296e-05 2.643688e-01