unuran.new {Runuran} | R Documentation |
Create a UNU.RAN object
Description
Create a new unuran
object in package Runuran that can be used
for sampling from the specified distribution.
The function ur
can then be used to draw a random
sample.
[Advanced] – Create generator object.
Usage
unuran.new(distr,method="auto")
Arguments
distr |
a string or an S4 class describing the distribution. |
method |
a string describing the random variate generation method. |
Details
This function creates an instance of S4 class
unuran
which contains a generator for the target
distribution. This distribution has to be provided as an instance of
S4 class unuran.distr
. Depending on the type of
distribution such an instance can be created by
unuran.cont.new
-
for univariate continuous distributions,
unuran.discr.new
-
for discrete distributions, and
unuran.cmv.new
-
for multivariate continuous distributions.
The generation can be chosen by passing method
to the UNU.RAN
String API. The default method, "auto"
tries to find an
appropriate method for the given distribution. However, this method is
experimental and is yet not very powerfull.
Once a unuran
object has been created it can be used to draw random
samples from the target distribution using ur
.
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.
See Also
See unuran
for the UNU.RAN class of generators.
See unuran.details
for printing details about the
generator object, and ur
and uq
for
sampling and quantile function, respectively.
For distribution objects see unuran.cont
,
unuran.discr
, and unuran.cmv
.
runif
, .Random.seed
about random number
generation in R.
Examples
## Use method 'TDR' (Transformed Density Rejection) to
## draw a sample of size 10 from a hyperbolic distribution with PDF
## f(x) = const * exp(-sqrt(1+x^2))
## restricted to domain [-1,2].
## We first have to define functions that return the log-density and
## its derivative, respectively. (We also could use the density itself.)
lf <- function (x) { -sqrt(1+x^2) }
dlf <- function (x) { -x/sqrt(1+x^2) }
## Next create the continuous distribution object.
d <- unuran.cont.new(pdf=lf,dpdf=dlf,islog=TRUE,lb=-1,ub=2)
## Create 'unuran' object. We choose method 'TDR' with
## immediate acceptance (IA) and parameter c=0.
gen <- unuran.new(distr=d, method="tdr; variant_ia; c=0")
## Now we can use this object to draw the sample.
## (Of course we can repeat this step as often as required.)
ur(gen,10)
## Here is some information about our generator object.
unuran.details(gen)