Skip to content
Back to formatted view

Raw Message

Message-ID: <6ade6f6c05050211026ffcc3ac@mail.gmail.com>
Date: 2005-05-02T18:02:06Z
From: Paul Smith
Subject: User-defined random variable
In-Reply-To: <4274972B.9080000@uni-bayreuth.de>

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