# Convert probability example to a distribution

Consider a box which contains 30 balls. 10 red, 10 white and 10 blue balls. There will be picked 4 balls randomly, without putting the balls back to the experiment.

My question is: How do I create a distribution of this senario, so I can find the probability that none of the 4 balls are red, and to calculate the mean and variance?

I am aware the math is:

$$\frac{20}{30} \times \frac{19}{29} \times \frac{18}{28} \times \frac{17}{27}=0.1768$$

But I need to convert it into a distribution and use the Probability function.

If we reformulate your question as:

Given a box with 30 balls, of which 10 are red, what is the probability that 4 balls drawn at random (without replacement) don't have any red balls in them

you can model it by the HypergeometricDistribution:

A hypergeometric distribution gives the distribution of the number of successes in $n$ draws from a population of size $n_{\mathrm{tot}}$ containing $n_{\mathrm{succ}}$ successes.

box[n_] := HypergeometricDistribution[n, 10, 30];
Probability[x == 0, x \[Distributed] box]
(* 323/1827 *)


or 0.176793 (use N or NProbability).

More generally, such problems can be modeled using theMultivariateHypergeometricDistribution. For the original question:

draw[n_] := MultivariateHypergeometricDistribution[n, {10, 10, 10}];
NProbability[r == 0, {r, b, w} \[Distributed] draw]
(* 0.176793 *)


We can also look at the probability of getting exactly 2 blue balls and at least 1 red ball:

NProbability[b == 2 && r > 0, {r, b, w} \[Distributed] draw]
(* 0.238095 *)


or the probability of getting exactly two balls, conditioned on the fact that at least one is red

NProbability[b == 2 \[Conditioned] r > 0, {r, b, w} \[Distributed] draw]
(* 0.289229 *)

• I was wondering. How would you calculate the conditional probability that there are exactly two blue balls in the sample, given that there are some red? 0.76969 – Jens Jensen Aug 7 '13 at 13:22
• @JensJensen See update – rm -rf Aug 7 '13 at 15:11