vcauchy: Variate Generation for Cauchy Distribution

View source: R/generators.R

vcauchyR Documentation

Variate Generation for Cauchy Distribution

Description

Variate Generation for Cauchy Distribution

Usage

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

Arguments

n

number of observations

location

Location parameter (default 0)

scale

Scale parameter (default 1)

stream

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

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 Cauchy distribution.

Cauchy 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::qcauchy is used to invert the uniform(0,1) variate(s). In this way, using vcauchy 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 Cauchy distribution has density
\deqn{f(x) = \frac{1}{\pi s} \ \left(1 + \left( \frac{x - l}{s} \right)^2
              \right)^{-1}}{
          f(x) = 1 / (\pi s (1 + ((x-l)/s)^2))}

for all x.

The mean is a/(a+b) and the variance is ab/((a+b)^2 (a+b+1)).

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 Cauchy 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::rcauchy

Examples

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qcauchy
 vcauchy(3, location = 3, scale = 1)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qcauchy
 vcauchy(3, 0, 3, stream = 1)
 vcauchy(3, 0, 3, stream = 2)

 set.seed(8675309)
 # NOTE: following inverts rstream::rstream.sample using stats::qcauchy
 vcauchy(1, 0, 3, stream = 1)
 vcauchy(1, 0, 3, stream = 2)
 vcauchy(1, 0, 3, stream = 1)
 vcauchy(1, 0, 3, stream = 2)
 vcauchy(1, 0, 3, stream = 1)
 vcauchy(1, 0, 3, stream = 2)

 set.seed(8675309)
 variates <- vcauchy(100, 0, 3, stream = 1)
 set.seed(8675309)
 variates <- vcauchy(100, 0, 3, stream = 1, antithetic = TRUE)


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