vlnorm: Variate Generation for Log-Normal Distribution

vlnormR Documentation

Variate Generation for Log-Normal Distribution

Description

Variate Generation for Log-Normal Distribution

Usage

vlnorm(
  n,
  meanlog = 0,
  sdlog = 1,
  stream = NULL,
  antithetic = FALSE,
  asList = FALSE
)

Arguments

n

number of observations

meanlog

Mean of distribution on log scale (default 0)

sdlog

Standard deviation of distribution on log scale (default 1)

stream

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

antithetic

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

asList

if FALSE (default), output only the generated random variates; otherwise, return a list with components suitable for visualizing inversion. See return for details

Details

Generates random variates from the log-normal distribution.

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

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

The log-normal distribution has density

\deqn{f(x) = \frac{1}{\sqrt{2 \pi} \sigma x}
                 e^{-(\log{x} - \mu)^2 / (2 \sigma^2)} }{
          f(x) = 1/(\sqrt(2 \pi) \sigma x) e^-((log x - \mu)^2 / (2 \sigma^2))}

where \mu and \sigma are the mean and standard deviation of the logarithm.

The mean is E(X) = \exp(\mu + 1/2 \sigma^2), the median is med(X) = \exp(\mu), and the variance is Var(X) = \exp(2\times \mu +\sigma^2)\times (\exp(\sigma^2)-1) and hence the coefficient of variation is sqrt(\exp(\sigma^2)-1) which is approximately \sigma when small (e.g., \sigma < 1/2).

Value

If asList is FALSE (default), return a vector of random variates.

Otherwise, return a list with components suitable for visualizing inversion, specifically:

u

A vector of generated U(0,1) variates

x

A vector of log-normal random variates

quantile

Parameterized quantile function

text

Parameterized title of distribution

Author(s)

Barry Lawson (blawson@bates.edu),
Larry Leemis (leemis@math.wm.edu),
Vadim Kudlay (vkudlay@nvidia.com)

See Also

rstream, set.seed, stats::runif

stats::rlnorm

Examples

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlnorm
 vlnorm(3, meanlog = 5, sdlog = 0.5)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlnorm
 vlnorm(3, 8, 2, stream = 1)
 vlnorm(3, 8, 2, stream = 2)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlnorm
 vlnorm(1, 8, 2, stream = 1)
 vlnorm(1, 8, 2, stream = 2)
 vlnorm(1, 8, 2, stream = 1)
 vlnorm(1, 8, 2, stream = 2)
 vlnorm(1, 8, 2, stream = 1)
 vlnorm(1, 8, 2, stream = 2)

 set.seed(8675309)
 variates <- vlnorm(100, 8, 2, stream = 1)
 set.seed(8675309)
 variates <- vlnorm(100, 8, 2, stream = 1, antithetic = TRUE)


simEd documentation built on Nov. 27, 2023, 1:07 a.m.