Hi, I would create a function rdiscrete that returns the value of a discrete random variable X defined on a subset which can change, and for the same probability for the issue, eg: X could sometimes take a value in the subset {2,3,4} with probability 1/3 for each issue, and sometimes X could take a value in the subset {2,3,4,5,6} with probability 1/5 for each issue, etc. The function should have one parameter only: a vector, composed by the values of the definition subset of X. Thank your for your help, Tristan Lorino ---------------------- ?cole Nationale V?t?rinaire d'Alfort - http://www.vet-alfort.fr, T?l. 01 43 96 70 33 M?l. tlorino at vet-alfort.fr Site personnel : http://daedale.free.fr -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Mon, 1 Jul 2002 tlorino at vet-alfort.fr wrote:> I would create a function rdiscrete that returns the value of a discrete randomThere already is a function rdiscrete in package e1071 which does what I would expect a function of that name to do.> variable X defined on a subset which can change, and for the same probability for > the issue, eg: > X could sometimes take a value in the subset {2,3,4} with probability 1/3 for each > issue, > and sometimes X could take a value in the subset {2,3,4,5,6} with probability > 1/5 for each > issue, > etc. > > The function should have one parameter only: a vector, composed by the values of > the definition subset of X.?sample, specifically sample(subset, 1). -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> Hi, > > I would create a function rdiscrete that returns the value of a discrete random > variable X defined on a subset which can change, and for the same probability for > the issue, eg: > X could sometimes take a value in the subset {2,3,4} with probability 1/3 for each > issue, > and sometimes X could take a value in the subset {2,3,4,5,6} with probability > 1/5 for each > issue, > etc. > > The function should have one parameter only: a vector, composed by the values of > the definition subset of X.have a look at `sample', Torsten> > Thank your for your help, > Tristan Lorino > > ---------------------- > ?cole Nationale V?t?rinaire d'Alfort - http://www.vet-alfort.fr, > T?l. 01 43 96 70 33 > M?l. tlorino at vet-alfort.fr > Site personnel : http://daedale.free.fr > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hi Tristan, how about: choose.from<-function(x) { x[ceiling(runif(1,0,length(x)))]} Cheers, Mike. > -----Original Message----- > From: owner-r-help at stat.math.ethz.ch > [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of > tlorino at vet-alfort.fr > Sent: 01 July 2002 10:24 > To: r-help at stat.math.ethz.ch > Subject: [R] Discrete random variable > > > Hi, > > I would create a function rdiscrete that returns the value > of a discrete random > variable X defined on a subset which can change, and for the > same probability for > the issue, eg: > X could sometimes take a value in the subset {2,3,4} with > probability 1/3 for each > issue, > and sometimes X could take a value in the subset {2,3,4,5,6} > with probability > 1/5 for each > issue, > etc. > > The function should have one parameter only: a vector, > composed by the values of > the definition subset of X. > > Thank your for your help, > Tristan Lorino > > ---------------------- > ?cole Nationale V?t?rinaire d'Alfort - http://www.vet-alfort.fr, > T?l. 01 43 96 70 33 > M?l. tlorino at vet-alfort.fr > Site personnel : http://daedale.free.fr > > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > .-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._