Using NProbability[] or Probability[] to work out the probability of 3 or more Heads from 4 coin tosses
Asked Answered
B

2

9

Is it possible to work out the probability of 3 or more Head from 4 coin tosses using the Probability or NProbability functions.

This is not a question about the trivial answer to this problem, it is more to get an understanding of how to solve this kind of problem with Mathematica using distributions.

So using 4 random variables from Distribution P

I was hoping something like this would do the trick, but it does not work. I get 0.

P = BernoulliDistribution[0.5];
vars = List[Distributed[a,P],Distributed[b,P],Distributed[c,P],Distributed[c,P]];
NProbability[Count[ {a,b,c,d}, 1] >= 3,  vars]

Any ideas would be greatly appreciated.

Banta answered 19/10, 2011 at 12:7 Comment(3)
Two errors there: c declared twice and d never and using Count instead of Total.Featherhead
Perhaps @Sjoerd is being too polite. After his modifications the OP's code worksCurvet
Ha! So it does. The double declaration was a copy paste error to the site. Using Total instead of Count did the trick. Many thanks guys.Banta
C
10

Not an expert using Mma for statistics here, but this seems to work:

l = TransformedDistribution[
       x + y + w + z, {x \[Distributed] BernoulliDistribution[0.5], 
                       y \[Distributed] BernoulliDistribution[0.5], 
                       z \[Distributed] BernoulliDistribution[0.5], 
                       w \[Distributed] BernoulliDistribution[0.5]}];

Table[NProbability[x > i, x \[Distributed] l], {i, -1, 4}]
(*
{1, 0.9375, 0.6875, 0.3125, 0.0625, 0.}
*)
Curvet answered 19/10, 2011 at 12:27 Comment(7)
Wow. Thanks so much! Explained it perfectly :)Banta
At the mma tech conference right now with leonid. We don't have much tine doing anything else.Featherhead
@Sjoerd Conference? With or without beer?Curvet
We had a social yesterday where we could try the products of local brewery. Leonid made us miss the last bus back, but Daniel was kind enough to being us back safe.Featherhead
Of course, we talked a lot about you and mr wizard. You were missed.Featherhead
Lots of stuff under NDA. Can't tell much.Featherhead
@Sjoerd Enjoy! And upload some photographs!Curvet
F
8
In[10]:= Probability[a + b + c + d >= 3, vars]

Out[10]= 0.3125

Coin flipping is easier described with a BinomialDistribution:

In[12]:= Probability[m >= 3, m \[Distributed] BinomialDistribution[4, 0.5]]

Out[12]= 0.3125
Featherhead answered 19/10, 2011 at 20:58 Comment(3)
Yes that is a lot cleaner. I did notice the TransformedDistribution as suggested by belisarius gets evaluated to BinomialDistribution. Thankyou :)Banta
@Banta I thought you did that on purpose because you wanted to know how to add random vars! Ha! Silly me.Curvet
@belisarius I did want to know how to add random vars and not just this yoy coin flip problem. So it being evaluated to a BinomialDist is just an interesting point in this particular case. What you provided is what really I wanted, a general understanding of how do these kinds of calculations. So you were spot on! :)Banta

© 2022 - 2024 — McMap. All rights reserved.