dari.new {Runuran} | R Documentation |
UNU.RAN random variate generator for continuous distributions with given probability mass function (PMF). It is based on Discrete Automatic Rejection Inversion (‘DARI’).
[Universal] – Rejection Method.
dari.new(pmf, lb, ub, mode=NA, sum=1, ...)
pmf |
probability mass function. (R function) |
lb |
lower bound of domain;
use -Inf if unbounded from left. (numeric, integer) |
ub |
upper bound of domain;
use Inf if unbounded from right. (numeric, integer) |
mode |
mode of distribution. (integer) |
sum |
sum over all “probabilities”. (numeric) |
... |
(optional) arguments for pmf |
This function creates an unuran
object based on ‘DARI’
(Discrete Automatic Rejection Inversion). It can be used to draw
samples of a discrete random variate with given probability mass function
using ur
.
The probabilities must be provided by a probability mass function
pmf
which must return non-negative numbers and which need not
be normalized (i.e., it can be any multiple of a PMF).
Moreover, the given function must be T_(-0.5)-concave;
this includes all log-concave distributions.
In addition the algorithm requires the location of the mode
.
If omitted then it is computed by a slow numerical search.
If the sum over all probabilities is different from 1 then a rough estimate of this sum is required.
Josef Leydold and Wolfgang H"ormann unuran@statmath.wu-wien.ac.at.
W. H"ormann, J. Leydold, and G. Derflinger (2004): Automatic Nonuniform Random Variate Generation. Springer-Verlag, Berlin Heidelberg. See Section 10.2 (Tranformed Probability Rejection).
ur
, unuran.new
, unuran
.
## Create a sample of size 100 for a Binomial distribution ## with 1000 number if observations and probability 0.2 gen <- dari.new(pmf=dbinom, lb=0, ub=1000, size=1000, prob=0.2) x <- ur(gen,100) ## Create a sample from a distribution with PMF ## p(x) = 1/x^3, x >= 1 (Zipf distribution) zipf <- function (x) { 1/x^3 } gen <- dari.new(pmf=zipf, lb=1, ub=Inf) x <- ur(gen,100)