[R] User-defined random variable

Paul Smith phhs80 at gmail.com
Mon May 2 20:02:06 CEST 2005


On 5/1/05, Matthias Kohl <Matthias.Kohl at uni-bayreuth.de> wrote:
> >>>I would like to know whether it is possible with R to define a
> >>>discrete random variable different from the ones already defined
> >>>inside R and generate random numbers from that user-defined
> >>>distribution.
> >>>
> >>Yes. One generic way is to specify the quantile function (as in
> >>qpois() etc.) and do qfun(runif(N)).
> >
> >If the support discrete but also finite, you can also use sample(), e.g.
> >
> >  sample(myset, N, replace = TRUE, prob = myprob)
> 
> one can also use our R package "distr" to generate discrete random
> variables. The subsequent code provides a function which generates an
> object of class "DiscreteDistribution" based on a finite support "supp".
> If "prob" is missing all elements in "supp" are equally weighted.

Thanks you for all your helpful replies to my question.

Paul




More information about the R-help mailing list