<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hypergeometric &#8211; paologironi blog</title>
	<atom:link href="https://www.gironi.it/blog/en/tag/hypergeometric/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.gironi.it/blog</link>
	<description>Scattered notes on (retro) computing, data analysis, statistics, SEO, and things that change</description>
	<lastBuildDate>Sun, 05 Jul 2026 20:03:03 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>The Hypergeometric Distribution</title>
		<link>https://www.gironi.it/blog/en/the-hypergeometric-distribution/</link>
					<comments>https://www.gironi.it/blog/en/the-hypergeometric-distribution/#respond</comments>
		
		<dc:creator><![CDATA[paolo]]></dc:creator>
		<pubDate>Fri, 24 Mar 2023 13:15:00 +0000</pubDate>
				<category><![CDATA[statistics]]></category>
		<category><![CDATA[distribution]]></category>
		<category><![CDATA[hypergeometric]]></category>
		<guid isPermaLink="false">https://www.gironi.it/blog/?p=3269</guid>

					<description><![CDATA[We have seen that the binomial distribution is based on the hypothesis of an infinite population N, a condition that can be practically realized by sampling from a finite population with replacement. If this does not occur, meaning if we are sampling from a population without replacement, we must use the hypergeometric distribution. (In reality, &#8230; <a href="https://www.gironi.it/blog/en/the-hypergeometric-distribution/" class="more-link">Continue reading<span class="screen-reader-text"> "The Hypergeometric Distribution"</span></a>]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">We have seen that the <a href="https://www.gironi.it/blog/en/probability-distributions-discrete-distributions-and-the-binomial/" data-type="post" data-id="807" target="_blank" rel="noreferrer noopener"><strong>binomial distribution</strong></a> is based on the hypothesis of an infinite population N, a condition that can be practically realized by sampling from a finite population <strong>with replacement</strong>.</p>



<p class="wp-block-paragraph">If this does not occur, meaning if we are sampling from a population <strong>without replacement</strong>, we must use the <strong>hypergeometric distribution</strong>. (In reality, if N is large, the hypergeometric probability density function tends towards the binomial).</p>



<p class="has-light-gray-background-color has-background wp-block-paragraph">The hypergeometric distribution is used to calculate the probability of obtaining a certain number of successes in a series of binary trials (yes or no), which are dependent and have a variable probability of success.</p>



<p class="wp-block-paragraph">The hypergeometric distribution allows us to answer questions like:</p>



<p class="has-light-gray-background-color has-background wp-block-paragraph">If I take a sample of size N, in which M elements meet certain requirements, what is the probability of drawing x elements that meet those requirements?</p>



<span id="more-3269"></span>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-f5fe3cc3      "
					data-scroll= "1"
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							What we will discuss						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#lets-start-with-the-formula" class="uagb-toc-link__trigger">Let&#039;s start with the formula</a><li class="uagb-toc__list"><a href="#the-hypergeometric-distribution-explained-with-examples" class="uagb-toc-link__trigger">The hypergeometric distribution explained with examples</a><li class="uagb-toc__list"><a href="#can-an-example-with-an-urn-and-balls-be-missing" class="uagb-toc-link__trigger">Can an example with an urn and balls be missing?</a><li class="uagb-toc__list"><a href="#further-examination-of-the-hypergeometric-distribution" class="uagb-toc-link__trigger">Further Examination of the Hypergeometric Distribution</a></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading">Let&#8217;s start with the formula</h2>



<p class="wp-block-paragraph">I express my distribution in the form of a formula:</p>



\(
f(X|N,M,n)=\frac{C^{N-M}_{n-x}\times C^M_x}{C^N_n} \
\)



<h2 class="wp-block-heading">The hypergeometric distribution explained with examples</h2>



<p class="wp-block-paragraph">We know that a batch of 30 pieces contains 6 malfunctioning pieces.<br>If I take a sample of 5 pieces, what is the probability of finding exactly 2 defective pieces?</p>



<p class="wp-block-paragraph">I&#8217;ll immediately write down the data:</p>



<ul class="wp-block-list">
<li>N=30 (<em>the total number of pieces in my batch</em>)</li>



<li>M=6 (<em>the total malfunctioning pieces present in the batch</em>)</li>



<li>x=2 (<em>I want to know the probability of finding 2 defective pieces</em>)</li>



<li>n=5 (<em>the size of my sample</em>)</li>
</ul>



<p class="wp-block-paragraph">Let&#8217;s see how to solve the same problem in R:</p>



<pre class="wp-block-code"><code># Definition of the hypergeometric distribution parameters
x &lt;- 2 # I want to know the probability of finding 2 defective pieces
n &lt;- 5 # the size of my sample
M &lt;- 6 # the total malfunctioning pieces present in the batch
N &lt;- 30 # the total number of pieces in my batch

# Probability calculation with the dhyper function
prob &lt;- dhyper(x, M, N - M, n)
prob</code></pre>



<p class="wp-block-paragraph">and I get the output:</p>



<pre class="wp-block-code"><code>[1] 0.2130437</code></pre>



<div class="wp-block-group has-background" style="background-color:#f5f7f9;margin-top:2.5rem;margin-bottom:2.5rem;padding-top:1.5rem;padding-right:1.5rem;padding-bottom:1rem;padding-left:1.5rem"><div class="wp-block-group__inner-container is-layout-constrained wp-container-core-group-is-layout-eed7543b wp-block-group-is-layout-constrained">

<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="975" height="600" src="https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-pmf-en-1.png" alt="Hypergeometric(N=30, M=6, n=5): the probability of finding x defective items in a sample of 5 drawn without replacement. The highlighted bar is the worked example, P(X = 2) = 0.213." class="wp-image-3995" srcset="https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-pmf-en-1.png 975w, https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-pmf-en-1-300x185.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">Hypergeometric(N=30, M=6, n=5): the probability of finding x defective items in a sample of 5 drawn without replacement. The highlighted bar is the worked example, P(X = 2) = 0.213.</figcaption></figure>

</div></div>



<div class="wp-block-group has-background" style="background-color:#f5f7f9;margin-top:2.5rem;margin-bottom:2.5rem;padding-top:1.5rem;padding-right:1.5rem;padding-bottom:1rem;padding-left:1.5rem"><div class="wp-block-group__inner-container is-layout-constrained wp-container-core-group-is-layout-eed7543b wp-block-group-is-layout-constrained">

<figure class="wp-block-image size-large"><img decoding="async" width="975" height="600" src="https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-vs-binomiale-en-1.png" alt="Without replacement you need the hypergeometric (blue); sampling with replacement, the binomial with p = 0.2 (orange) would suffice. The two distributions are close and would coincide for very large N." class="wp-image-3996" srcset="https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-vs-binomiale-en-1.png 975w, https://www.gironi.it/blog/wp-content/uploads/2026/07/ipergeometrica-vs-binomiale-en-1-300x185.png 300w" sizes="(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px" /><figcaption class="wp-element-caption">Without replacement you need the hypergeometric (blue); sampling with replacement, the binomial with p = 0.2 (orange) would suffice. The two distributions are close and would coincide for very large N.</figcaption></figure>

</div></div>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h2 class="wp-block-heading">Can an example with an urn and balls be missing?</h2>



<div class="wp-block-uagb-image aligncenter uagb-block-eb7e4992 wp-block-uagb-image--layout-default wp-block-uagb-image--effect-static wp-block-uagb-image--align-center"><figure class="wp-block-uagb-image__figure"><img decoding="async" srcset="https://www.gironi.it/blog/wp-content/uploads/2023/03/07bed749-7708-4f32-8b92-d46342b9f532-300x300.jpeg " src="https://www.gironi.it/blog/wp-content/uploads/2023/03/07bed749-7708-4f32-8b92-d46342b9f532-300x300.jpeg" alt="Hypergeometric distribution: drawing white or black balls from an urn." class="uag-image-2945" width="300" height="300" title="" loading="lazy"/></figure></div>



<p class="wp-block-paragraph">Let&#8217;s now make another example: let&#8217;s estimate the probability that in an urn with 10 white balls and 5 black ones, drawing 4 balls without replacement, we get 3 white and 1 black. So:</p>



<ul class="wp-block-list">
<li>x=3 Number of white balls drawn</li>



<li>n=4 Number of balls drawn</li>



<li>M=5 Number of black balls</li>



<li>N = 15 Total number of balls</li>
</ul>



<p class="wp-block-paragraph">We have seen that in R, it&#8217;s possible to use the <code>dhyper</code> function to calculate the probability of drawing 3 white balls and 1 black ball from the described urn.</p>



<p class="wp-block-paragraph">Here&#8217;s the R code:</p>



<pre class="wp-block-code"><code># Definition of the hypergeometric distribution parameters
x &lt;- 3 # Number of white balls drawn
n &lt;- 4 # Number of balls drawn
M &lt;- 5 # Number of black balls
N &lt;- 15 # Total number of balls

# Probability calculation with the dhyper function
prob &lt;- dhyper(x, M, N - M, n)
prob</code></pre>



<p class="wp-block-paragraph">The probability of drawing 3 white balls and 1 black ball is therefore 0.07326007, or about 7.33%.</p>



<h2 class="wp-block-heading"><strong>Further Examination of the Hypergeometric Distribution</strong></h2>



<ul class="wp-block-list">
<li><a href="https://it.wikipedia.org/wiki/Distribuzione_ipergeometrica" target="_blank" rel="noreferrer noopener">Hypergeometric Distribution &#8211; Wikipedia</a></li>



<li><a href="https://www.webtutordimatematica.it/materie/statistica-e-probabilita/distribuzioni-di-probabilita-discrete/distribuzione-ipergeometrica" target="_blank" rel="noreferrer noopener">Hypergeometric Distribution &#8211; WebTutorDiMatematica.it</a></li>



<li><a href="https://www.okpedia.it/distribuzione-ipergeometrica" target="_blank" rel="noreferrer noopener">Hypergeometric Distribution &#8211; Okpedia</a></li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity"/>



<h3 class="wp-block-heading">Further Reading</h3>



<p class="wp-block-paragraph">For an accessible walk through the discrete distributions &mdash; hypergeometric included &mdash; <a href="https://www.amazon.it/dp/8867319396?tag=consulenzeinf-21&#038;ascsubtag=the-hypergeometric-distribution" rel="nofollow sponsored noopener" target="_blank"><em>Finalmente ho capito la statistica</em></a> by Maurizio De Pra (Italian edition) covers them with plenty of worked examples.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.gironi.it/blog/en/the-hypergeometric-distribution/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
