Re: [R] User-defined random variable

From: Achim Zeileis <Achim.Zeileis_at_wu-wien.ac.at>
Date: Sun 01 May 2005 - 01:26:29 EST

On Sat, 30 Apr 2005, Peter Dalgaard wrote:

> Paul Smith <phhs80@gmail.com> writes:
>
> > 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.
>
> 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)

Z

> --
> O__ ---- Peter Dalgaard Blegdamsvej 3
> c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
>
> ______________________________________________
> 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
>



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 Sun May 01 01:29:49 2005

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