# [R] "rbinom" not using probability of success right

From: Kyle Matoba <kmmatoba_at_ucdavis.edu>
Date: Thu, 29 May 2008 09:26:47 -0700 (PDT)

Message: 24
Date: Wed, 28 May 2008 05:53:26 -0700 (PDT) From: Philip Twumasi-Ankrah <nana_kwadwo_derkyi_at_yahoo.com> Subject: [R] "rbinom" not using probability of success right To: r-help_at_r-project.org
Message-ID: <374543.31047.qm@web39505.mail.mud.yahoo.com> Content-Type: text/plain

I am trying to simulate a series of ones and zeros (1 or 0) and I am using "rbinom" but
realizing that the number of successes expected is not accurate. Any advice out there.

This is the example:

N<-500
status<-rbinom(N, 1, prob = 0.15)
count<-sum(status)

15 percent of 500 should be 75 but what I obtain from the "count" variable is 77 that
gives the probability of success to be 0.154. Not very good.

Is there another way beyond using "sample" and "rep" together?

I understand you correctly you want there to be exactly 75 ones. If this is what you are trying to do then using pseudorandom variables is the incorrect way of going about it. Your suggestion of sample(c(rep (0,545),rep(1,75))) seems to me to be the best way of going about it since conceptually this is what you are doing: taking permutation of a fixed set of numbers.

Best,

Kyle

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 29 May 2008 - 17:22:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 29 May 2008 - 17:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.