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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed, 28 May 2008 14:18:54 +0100 (BST)

You asked for each of 500 to be included with probability 0.15, not for 15% of 500. If you want the latter, use sample, e.g.

sample(c(rep(1,75), rep(0,425)))

And to see if your 77 is reasonable for binomial sampling:

> binom.test(77, 500, 0.15)

Exact binomial test

data: 77 and 500
number of successes = 77, number of trials = 500, p-value = 0.8022 alternative hypothesis: true probability of success is not equal to 0.15 95 percent confidence interval:
0.1234860 0.1886725
sample estimates:

probability of success

```                  0.154

```

so it certainly is.

On Wed, 28 May 2008, Philip Twumasi-Ankrah wrote:

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

[...]

```--
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help