Learn R Programming

simEd (version 1.0.3)

vweibull: Variate Generator for the Weibull Distribution

Description

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

Usage

vweibull(n, shape, scale = 1, stream = NULL, antithetic = FALSE)

Arguments

n

number of observations

shape, scale

shape and scale parameters (must be positive)

stream

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

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 Weibull random variates.

Details

Generates random variates from the Weibull distribution.

Weibull 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::qweibull is used to invert the uniform(0,1) variate(s). In this way, using vweibull provides a monotone and synchronized Weibull variate generator, although not particularly fast.

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

If scale is omitted, it assumes the default value of 1.

The Weibull distribution with parameters shape = \(a\) and scale = \(b\) has density

$$f(x) = \frac{a}{b} \left(\frac{x}{b}\right)^{a-1} e^{-(x/b)^a}$$

for \(x \ge 0\), \(a > 0\), and \(b > 0\).

See Also

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

Examples

Run this code
# NOT RUN {
set.seed(8675309)
vweibull(3, shape = 2, scale = 1)  # inverts stats::runif using stats::qweibull

set.seed(8675309)
vweibull(3, shape = 2, scale = 1, stream = 1)  # inverts rstream.sample using stats::qweibull
vweibull(3, shape = 2, scale = 1, stream = 2)

set.seed(8675309)
vweibull(1, shape = 2, scale = 1, stream = 1)  # inverts rstream.sample using stats::qweibull
vweibull(1, shape = 2, scale = 1, stream = 2)
vweibull(1, shape = 2, scale = 1, stream = 1)
vweibull(1, shape = 2, scale = 1, stream = 2)
vweibull(1, shape = 2, scale = 1, stream = 1)
vweibull(1, shape = 2, scale = 1, stream = 2)

set.seed(8675309)
variates <- vweibull(1000, shape = 2, scale = 1, stream = 1)
set.seed(8675309)
variates <- vweibull(1000, shape = 2, scale = 1, stream = 1, antithetic = TRUE)
# }

Run the code above in your browser using DataLab