Description Usage Arguments Details Value Author(s) References See Also Examples

UNU.RAN random variate generator for discrete distributions with given probability mass function (PMF). It is based on Discrete Automatic Rejection Inversion (‘DARI’).

[Universal] – Rejection Method.

1 2 |

`pmf` |
probability mass function. ( |

`lb` |
lower bound of domain;
use |

`ub` |
upper bound of domain;
use |

`mode` |
mode of distribution. (integer) |

`sum` |
sum over all “probabilities”. (numeric) |

`...` |
(optional) arguments for |

`distr` |
distribution object. (S4 object of class |

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`

.

Function `pmf`

must be postive but need not be normalized
(i.e., it can be any multiple of a probability mass function).

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.

Alternatively, one can use function `darid.new`

where the object
`distr`

of class `"unuran.discr"`

must contain all required
information about the distribution.

An object of class `"unuran"`

.

Josef Leydold and Wolfgang H\"ormann [email protected].

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.discr`

,
`unuran.new`

,
`unuran`

.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ```
## 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)
## Alternative approach
distr <- udbinom(size=100,prob=0.3)
gen <- darid.new(distr)
x <- ur(gen,100)
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.