[R] Calculate probabilty

rex.dwyer at syngenta.com rex.dwyer at syngenta.com
Fri Feb 25 18:40:38 CET 2011


Are you clear about the question you are asking?  Do you want to know whether there are 6 balls or at least 6 balls?  (It sounds like "at least".)  Do you want to know whether there are at least 6 balls in the first box, or at least 6 balls in exactly one box or at least 6 balls in at least one box?

This is the probability that there are exactly 6 balls in the first box:
> dbinom(6,142,1/491)
[1] 5.53366e-07
>
This is the probability that there are MORE THAN 6 balls in the first box:  (NOT "at least 6")
> 1-pbinom(6,142,1/491)
[1] 2.272026e-08
> sum(sapply(7:142, function(i) dbinom(i,142,1/491)))
[1] 2.272026e-08
> 1-sum(sapply(0:6, function(i) dbinom(i,142,1/491)))
[1] 2.272026e-08

This is probability that there are at least 6 balls in the first box:
> 1-pbinom(5,142,1/491)
[1] 5.760862e-07

You can get all this from ?dbinom, but it pretty confusing that the argument n and the italic n in the details are totally different things, italic n = argument size.  (Likewise, italic p = argument prob, not argument p.)

Questions about more than one box are a little harder since the boxes are not independent.

HTH,
Rex

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Fabrice Tourre
Sent: Thursday, February 24, 2011 3:51 PM
To: r-help at r-project.org
Subject: [R] Calculate probabilty

Hi List,

I have a question to calculate probability using R.

There are 491 boxes and 142 balles. If the ball randomly put into the
box. How to calculate the probability of six or more there are in one
box?

I have try :

dbinom(6,142,1/491)

1-pbinom(6,142,1/491)

But I think I have some unclear about the dbinom and pbinom.

Thank you very much in advance.

______________________________________________
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.




message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. 


More information about the R-help mailing list