Skip to content

User-defined random variable

3 messages · Paul Smith, Peter Dalgaard, Achim Zeileis

#
Dear All

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.

Thanks in advance,

Paul
#
Paul Smith <phhs80 at gmail.com> writes:
Yes. One generic way is to specify the quantile function (as in
qpois() etc.) and do qfun(runif(N)).
#
On Sat, 30 Apr 2005, Peter Dalgaard wrote:

            
If the support discrete but also finite, you can also use sample(), e.g.

  sample(myset, N, replace = TRUE, prob = myprob)

Z