Learn R Programming

simEd (version 2.0.1)

vlogis: Variate Generation for Logistic Distribution

Description

Variate Generation for Logistic Distribution

Usage

vlogis(
  n,
  location = 0,
  scale = 1,
  stream = NULL,
  antithetic = FALSE,
  asList = FALSE
)

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 logistic random variates

quantile

Parameterized quantile function

text

Parameterized title of distribution

Arguments

n

number of observations

location

Location parameter

scale

Scale parameter (default 1)

stream

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

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

Author

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

Details

Generates random variates from the logistic distribution.

Logistic 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::qlogis is used to invert the uniform(0,1) variate(s). In this way, using vlogis 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 logistic distribution with location \(= \mu\) and scale \(= \sigma\) has distribution function

$$F(x) = \frac{1}{1 + e^{-(x - \mu) / \sigma}}$$

and density

$$f(x) = \frac{1}{\sigma} \frac{e^{(x-\mu)/\sigma}} {(1 + e^{(x-\mu)/\sigma})^2}$$

It is a long-tailed distribution with mean \(\mu\) and variance \(\pi^2 / 3 \sigma^2\).

See Also

Examples

Run this code
 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlogis
 vlogis(3, location = 5, scale = 0.5)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlogis
 vlogis(3, 5, 1.5, stream = 1)
 vlogis(3, 5, 1.5, stream = 2)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qlogis
 vlogis(1, 5, 1.5, stream = 1)
 vlogis(1, 5, 1.5, stream = 2)
 vlogis(1, 5, 1.5, stream = 1)
 vlogis(1, 5, 1.5, stream = 2)
 vlogis(1, 5, 1.5, stream = 1)
 vlogis(1, 5, 1.5, stream = 2)

 set.seed(8675309)
 variates <- vlogis(100, 5, 1.5, stream = 1)
 set.seed(8675309)
 variates <- vlogis(100, 5, 1.5, stream = 1, antithetic = TRUE)

Run the code above in your browser using DataLab