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

Kyle Matoba kmmatoba at ucdavis.edu
Thu May 29 18:26:47 CEST 2008


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 at 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



More information about the R-help mailing list