Learn R Programming

simEd (version 1.0.3)

vexp: Variate Generator for the Exponential Distribution

Description

Generates random variates from the exponential distribution, with options for independent streams and antithetic variates.

Usage

vexp(n, rate = 1, stream = NULL, antithetic = FALSE)

Arguments

n

number of observations

rate

rate parameter; must be positive

stream

if NULL (default), uses stats::runif to generate uniform variates to invert via stats::qexp; otherwise, an integer in 1:25 indicates the rstream stream from which to generate uniform variates to invert via stats::qexp

antithetic

if FALSE (default), inverts \(u\) = uniform(0,1) variate(s) generated via either stats::runif or rstream::rstream.sample; otherwise, uses \(1 - u\)

Value

A vector of exponential random variates.

Details

Generates random variates from the exponential distribution.

Exponential variates are generated by inverting uniform(0,1) variates produced either by stats::runif (if stream is NULL) or by rstream::rstream.sample (if stream is not NULL). In either case, stats::qexp is used to invert the uniform(0,1) variate(s). In this way, using vexp provides a monotone and synchronized exponential variate generator, although not particularly fast.

The stream indicated must be an integer between 1 and 25 inclusive.

If rate is not specified, it assumes the default value of 1.

The exponential distribution with rate \(\lambda\) has density

$$f(x) = \lambda e^{-\lambda x}$$

for \(x \ge 0\).

See Also

stats::rexp, stats::runif, rstream, set.seed

Examples

Run this code
# NOT RUN {
set.seed(8675309)
vexp(3)  # inverts stats::runif using stats::qexp

set.seed(8675309)
vexp(3, rate = 2)  # inverts stats::runif using stats::qexp

set.seed(8675309)
vexp(3, rate = 2, stream = 1) # inverts rstream::rstream.sample using stats::qexp
vexp(3, rate = 2, stream = 2)

set.seed(8675309)
vexp(1, rate = 2, stream = 1) # inverts rstream::rstream.sample using stats::qexp
vexp(1, rate = 2, stream = 2)
vexp(1, rate = 2, stream = 1)
vexp(1, rate = 2, stream = 2)
vexp(1, rate = 2, stream = 1)
vexp(1, rate = 2, stream = 2)

set.seed(8675309)
interarrivals <- vexp(1000, rate = 1,    stream = 1)
services      <- vexp(1000, rate = 10/9, stream = 2)

set.seed(8675309)
interarrivals <- vexp(1000, rate = 1,    stream = 1, antithetic = TRUE)
services      <- vexp(1000, rate = 10/9, stream = 2, antithetic = TRUE)
# }

Run the code above in your browser using DataLab