Re: [S] Question - Coding numeric vectors

Lutz Prechelt (prechelt@ira.uka.de)
Wed, 25 Mar 1998 16:11:15 +0100


> I am attempting to simulate termite behavior with regard to selection of
> feeding sites. In setting up the simulation I need to generate what are
> essentially multinomial random numbers to represent which feeding site
> was chosen. Since I am unaware of a multinomial random number generator
> in S-plus (please enlighten me if I have missed something here)
>
> > probs <- c(.25, .35, .4, 0, 0) # Note the zero probabilities are required

Try this:

sites <- c(rep(1,25), rep(2,35), rep(3,40), rep(4,0), rep(5,0))

and then use

sample(sites,1)

to pick a site at random with the required probabilities.

Lutz

Lutz Prechelt http://wwwipd.ira.uka.de/~prechelt/ | Whenever you
Institut f. Programmstrukturen und Datenorganisation | complicate things,
Universitaet Karlsruhe; D-76128 Karlsruhe; Germany | they get
(Phone: +49/721/608-4068, FAX: +49/721/608-7343) | less simple.
>>> Ever had negative research results? http://wwwipd.ira.uka.de/fnr <<<

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news