srou.new {Runuran} | R Documentation |
UNU.RAN generator based on Simple Ratio-Of-Uniforms Method (SROU)
Description
UNU.RAN random variate generator for continuous distributions with given probability density function (PDF). It is based on the Simple Ratio-Of-Uniforms Method (‘SROU’).
[Universal] – Rejection Method.
Usage
srou.new(pdf, lb, ub, mode, area, islog=FALSE, r=1, ...)
sroud.new(distr, r=1)
Arguments
pdf |
probability density function. (R function) |
lb |
lower bound of domain;
use |
ub |
upper bound of domain;
use |
mode |
location of the mode. (numeric) |
area |
area below |
islog |
whether |
... |
(optional) arguments for |
distr |
distribution object. (S4 object of class |
r |
adjust algorithm to heavy-tailed distribution. (numeric) |
Details
This function creates a unuran
object based on ‘SROU’
(Simple Ratio-Of-Uniforms Method). It can be used to draw samples of a
continuous random variate with given probability density function
using ur
.
The density pdf
must be positive but need not be normalized
(i.e., it can be any multiple of a density function).
It must be T_c
-concave for
c = -r/(r+1)
; this includes all log-concave
distributions.
The (exact) location of the mode
and the area below
the pdf
are essential.
Alternatively, one can use function sroud.new
where the object
distr
of class "unuran.cont"
must contain all required
information about the distribution.
The acceptance probability decreases with increasing parameter
r
. Thus it should be as small as possible. On the other hand it
must be sufficiently large for heavy tailed distributions.
If possible, use the default r=1
.
Compared to tdr.new
it has much slower marginal
generation times but has a faster setup and is numerically more
robust. Moreover, It also works for unimodal distributions with tails
that are heavier than those of the Cauchy distribution.
Value
An object of class "unuran"
.
Author(s)
Josef Leydold and Wolfgang H\"ormann unuran@statmath.wu.ac.at.
References
W. H\"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. Sections 6.3 and 6.4.
See Also
ur
,
unuran.cont
,
unuran.new
,
unuran
.
Examples
## Create a sample of size 100 for a Gaussian distribution.
pdf <- function (x) { exp(-0.5*x^2) }
gen <- srou.new(pdf=pdf, lb=-Inf, ub=Inf, mode=0, area=2.506628275)
x <- ur(gen,100)
## Create a sample of size 100 for a Gaussian distribution.
## Use 'dnorm'.
gen <- srou.new(pdf=dnorm, lb=-Inf, ub=Inf, mode=0, area=1)
x <- ur(gen,100)
## Alternative approach
distr <- udnorm()
gen <- sroud.new(distr)
x <- ur(gen,100)