Re: [R] User-defined random variable

From: Paul Smith <phhs80_at_gmail.com>
Date: Tue 03 May 2005 - 04:02:06 EST

On 5/1/05, Matthias Kohl <Matthias.Kohl@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



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue May 03 04:08:05 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:32 EST