Hypergeometric distribution appears to have hidden problems

When I was writing a computer program to calculate hypergeometric distributions probabilities I had some funny results. This is because I just used the condition I found in a stats book. The book says: p(x) = formula with x =0;1;....;n where n is the size of the sample drawn and p(x) = 0 otherwise. I stuck this condition into my computer program and had some funny results until I started wondering if the single condition was adequate. If you have a red balls and b white balls and you draw n balls from this set, then obviously n must be less than a+b because there are only a+b balls. Say taking out a red ball is success. Now obviously p(x) must have x less than or equal to a because you cannot have a probability of drawing more than a red balls (or p=0 if you like).
NOW: If on n draws you have x red balls drawn the rest (n-x) must be white balls.
Now you have to satisfy the condition that n-x (number of white balls drawn) is less than or equal to b (there are only b white balls). After I stuck in all these conditions I started to have success. To analyse: (n-x)<=b means that when x=0 then (n-0)<=b.
When x=a then (n-a)<=b. If you stick all these sorts of conditions into the program it works. Seems to me programming gets you thinking of all the necessary conditions, and I would like to add to the conditions given in stats books re the hypergeometric distribution. Anyone agree?
Last edited:
It is not specifically stated that n-x must be less than or equal to b. Obviously the probability of (n-x)>b is zero.
Last edited: