Learn R Programming

Runuran (version 0.22.0)

unuran.new: 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.

code

ur

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 [object Object],[object Object],[object Object]

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

Run this code
## 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)

Run the code above in your browser using DataLab