# Probability of choosing N out of K correctly from a total population of X [duplicate]

Out of a total population of 50 items, there are 20 "correct" items, what is the probability of me selecting 11 (or more) of these correct items if I randomly choose 20?

How can I do this in R? I was thinking of using binom.test() but that assumes replacement, and my questions involves 'no-replacement' when making your selections.

• $\sum_{k=11}^{20} {20\choose k}{30\choose 20-k}/{50\choose 20}\approx 7.05\%$ – Zen Jan 23 '14 at 0:28
• We welcome questions like this, @justin, but we treat them differently. Please tell us what you understand thus far, what you've tried & where you are stuck, & we'll try to provide hints to get you unstuck. To better understand the process, you should read the wiki for the [self-study] tag. – gung - Reinstate Monica Jan 23 '14 at 0:46
• The R translation of the equation in @Zen's comment would be: sum(choose(20, 11:20) * choose(30, 20 - (11:20))) / choose(50, 20). The phyper() version below is certainly more economical on the fingers. – Reinstate Monica - G. Simpson Jan 23 '14 at 1:52
• Thanks! Super helpful -- yes the phyper() function mentioned below is certainly the 'optimal' answer from a usability standpoint, but it definitely helps to see how its works from the combinatoric perspective in this response – justin Jan 23 '14 at 21:59
• @gung : sorry, i'm new here and didn't know of the strict guidelines for question asking. I will read the wiki. FWIW the searching I previously did on the site, such as the question which you claim this is a dup of was wording poorly from the submitter, as well as the responses were highly technical. the succint nature of my questions and the excellent succint responses by those on this thread is MUCH more helpful to me as someone who hasn't had a statistics class in about 10 years. – justin Jan 23 '14 at 22:05

You're correct that it's not binomial. That's for sampling with replacement, this is sampling without replacement (a 'drawing balls from an urn' or 'drawing from a deck of cards' type model, rather than the more common 'tossing a coin'/'rolling a die' model).

This is just a straight hypergeometric probability calculation. (This is discussed in many basic books on probability.)

See Wikipedia on the hypergeometric distribution.

In particular, in the example (involving Texas Hold 'Em), the event 'the card is a club' corresponds to your 'chose a correct item'.

You can also find some more questions on the hypergeometric here on CV with some searches.

In R, the phyper function (with lower.tail=FALSE) evaluates these "$\geq$" probabilities (well, it actually evaluates $>$, but you get $\geq$ by subtracting 1 from the argument). See ?phyper.

> phyper(11-1,20,50-20,20,lower.tail=FALSE)
[1] 0.07051887