# How to calculate probability for n dependent events

I have a dataset containing some approx. 11 million instances, all of which can be labelled as either class A or class B. I know a priori that approx. 1,000 of these instances belong to class A, and the rest are class B. However none of the instances are actually labelled. So, I would like to be able to sample these 11 million instances, and know the probability of my sample containing an instance from class A.

For instance:

If I take 30,000 random samples without replacement from the 11 million instances (which are i.i.d), what is the probability that my sample will contain an instance from class A (size 1,000 instances)? Is this even possible to calculate?

Also is it possible for me to approximately bound how many instances from class A would be in this sample (for varying sample sizes)? Is there a formula I can simply plug my values into?

Apologies if this problem seems simple, but stats has never been a strength of mine. This isn't a homework task, but a work problem. I'm trying to build a training set from a domain outside my own, whereby I need to minimise the prevalence of class A in my training set. Class A are positive examples which need to be removed - unfortunately when the data was first processed the data labels were discarded :-/ . It would take years to label them manually and even that process is prone to human error!

Thanks.

Update:

For those with a similar problem I found methods in the Apache Commons Mathematics Library for calculating binomials and more importantly the Hypergeometic Distribution which be of use.

The hyper() command available in R (suggested by @whuber) also proved very useful. Would certainly recommend. For instance to produce a plot you can use:

plot(dhyper(0:10,1000,11000000-1000,30000),type="b",xlab="x label",ylab="y label", main="Title")

Where 0:10 is the range. 1000 is the number of positive marbles in the urn. 11000000-1000 is the number of negative marbles in the urn. 30000 is the number of draws.

This will produce a plot with lines and points which is type "b". Other types are described online (I would post more links, but I can't with such low reputation).

Thanks again for the help everyone.

-
If they were selected at random, and w/ replacement, you would have a simple binomial. The only complication is that by not replacing the cases, there is a different probability of an A on each draw, & conditional on what's been drawn thus far. There is still an equation that will give you that distribution, but I don't know it off the top of my head. –  gung Oct 24 '12 at 14:34
@gung strictly speaking, that's hypergeometric, though the binomial would be an excellent approximation with such a large population and large numbers in each class. –  Glen_b Oct 24 '12 at 21:48
@Glen_b, thanks for the tip! –  gung Oct 24 '12 at 23:09

What you want is the Hypergeometric distribution. This addresses the following question: If I have an urn with $B$ black balls and $R$ red balls, and I draw $S$ balls by random, what is the probability of having $X$ or more red balls? This is exactly the situation that you have

You will find HGD implementations in many programming languages/environments.

As noted, if your sample is very small relative to the other sizes, you can get a good approximation with the binomial distribution

-
+1 R computes the full distribution of the counts of "instances from class A" in the sample accurately even for such large parameters, as in dhyper(0:10, 1000, 11000000-1000, 30000). –  whuber Oct 24 '12 at 16:28
@Bitwise thats precisely what I was after, thanks! Really appreciate the help. Thanks too @gung! –  ScienceGuyRob Oct 24 '12 at 17:40
Thanks @whuber I'm going to check this out now, it sounds perfect - been meaning to look at R for a while, no time like the present! –  ScienceGuyRob Oct 24 '12 at 17:44
@ScienceGuyRob Note that the binomial and Poisson will both give very good approximations to the probabilities you're likely to want in your situation (i.e. with those specific numbers). –  Glen_b Oct 24 '12 at 21:57
thanks @Glen_b the approximations may be sufficient for my task. –  ScienceGuyRob Oct 26 '12 at 10:05