Generates random variates from the geometric distribution, with options for independent streams and antithetic variates.
vgeom(n, prob, stream = NULL, antithetic = FALSE)
number of observations
probability of success in each trial (0 prob
if NULL
(default), uses stats::runif
to generate uniform variates to invert via stats::qgeom
;
otherwise, an integer in 1:25 indicates the rstream
stream
from which to generate uniform variates to invert via
stats::qgeom
if FALSE
(default), inverts stats::runif
or
rstream::rstream.sample
; otherwise, uses
A vector of geometric random variates.
Generates random variates from the geometric distribution.
Geometric 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::qgeom
is used to invert the
uniform(0,1) variate(s).
In this way, using vgeom
provides a monotone and synchronized
geometric variate generator, although not particularly fast.
The stream indicated must be an integer between 1 and 25 inclusive.
The geometric distribution with parameter prob
=
for
# NOT RUN {
set.seed(8675309)
vgeom(3, prob = 0.3) # inverts stats::runif using stats::qgeom
set.seed(8675309)
vgeom(3, 0.3, stream = 1) # inverts rstream::rstream.sample using stats::qgeom
vgeom(3, 0.3, stream = 2)
set.seed(8675309)
vgeom(1, 0.3, stream = 1) # inverts rstream::rstream.sample using stats::qgeom
vgeom(1, 0.3, stream = 2)
vgeom(1, 0.3, stream = 1)
vgeom(1, 0.3, stream = 2)
vgeom(1, 0.3, stream = 1)
vgeom(1, 0.3, stream = 2)
set.seed(8675309)
variates <- vgeom(1000, prob = 0.3, stream = 1)
set.seed(8675309)
variates <- vgeom(1000, prob = 0.3, stream = 1, antithetic = TRUE)
# }
Run the code above in your browser using DataLab