Skip to content

Instantly share code, notes, and snippets.

@JohnDeJesus22
Created October 28, 2019 01:40
Show Gist options
  • Save JohnDeJesus22/938cbe1de15792d2304925753929f394 to your computer and use it in GitHub Desktop.
Save JohnDeJesus22/938cbe1de15792d2304925753929f394 to your computer and use it in GitHub Desktop.
Hypergeometric PMF
import numpy as np
import matplotlib.pyplot as plt
from scipy.special import comb
def hypergeom_pmf(N, A, n, x):
'''
Probability Mass Function for Hypergeometric Distribution
:param N: population size
:param A: total number of desired items in N
:param n: number of draws made from N
:param x: number of desired items in our draw of n items
:returns: PMF computed at x
'''
Achoosex = comb(A,x)
NAchoosenx = comb(N-A, n-x)
Nchoosen = comb(N,n)
return (Achoosex)*NAchoosenx/Nchoosen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment