# Probability Distribution of a Multivariate Hypergeometric distribution and maximum probability

Hello to all Mathematica Users! I have this question:

Consider a box which contains 69 balls. 17 red, 1 white, 29 blue and 22 green balls. There will be picked 7 balls randomly, without putting the balls back to the experiment.

My question is: How do I create a probability distribution of all the possible combinations and to visualize it? And then I would like to find the combination with the higher probability and the mean.

I know that I have to use "Multivariate Hypergeometric distribution", and I know how to compute the probability of a particular combination, but not how to find the more probable combination and the mean of the whole distribution.

• Welcome to the forum. We appreciate it if you post whatever code you've come up with so far when posting questions -- makes it easier for us to help. – mfvonh Jun 26 '14 at 15:57

Define the distribution:

dist = MultivariateHypergeometricDistribution[7, balls = {17, 1, 29, 22}];


Just use the relevant functions for summary statistics:

Through[{Mean, Variance}[dist]] // N


{{1.72464, 0.101449, 2.94203, 2.23188}, {1.18505, 0.0911573, 1.55504, 1.38613}}

This is challenging to visualize because it is 4-dimensional. One option is to take some random draws and see what pattern they reveal:

BlockRandom[
SeedRandom@8674309;
sample = RandomVariate[dist, 100]];
BarChart[sample,
ChartLayout -> "Stacked",
ChartStyle -> {Red, White, Blue, Green},
AspectRatio -> 1/5,
ImageSize -> 500]


There are other ways to visualize this, of course, but we'd need to know more about your needs to make useful suggestions.

You'll need the PDF for probabilities:

pdf = PDF[dist, vars = {i, j, k, l}];


You can check the probability of any particular combination using rules (this is a piecewise function):

pdf /. {i -> 1, j -> 1, k -> 3, l -> 2} // N


0.0132999

And you can maximize this function to get the most likely combination:

MapAt[N, Maximize[pdf, vars, Integers], 1]


{0.106399, {i -> 2, j -> 0, k -> 3, l -> 2}}

• What you have written is quite interesting, but one thing that I don't understand is: Why we have to use the Probability Density Function if we are working with a Multivariate Discrete distribution? – user29859 Jun 27 '14 at 12:26