Hypergeometric

Describes the probability of 𝑘 k successes in 𝑛 n draws from a finite population of size 𝑁 N containing exactly 𝐾 K successes, without replacement. It is used when the sample is drawn from a population without replacement, making the trials dependent on each other.

Create a new Hypergeometric distribution

Hypergeometric X = Hypergeometric(K, N, n); 

creates a discrete Hypergeometric probability distribution.

Distribution properties:

Property
Type/Return type
Description

K

int

Successes in population.

N

int

Population size.

n

int

Sample size.

E()

double

Returns the expected value of success items from a sample size n, from a population size N.

D()

double

Represents variance, that measures the spread of dispersion of the random variable around its expected value E(X).

P(int k)

double

Probability of getting exactly 𝑘 successes in 𝑛 draws from a population of size 𝑁 with 𝐾 successes: P(X = k)

P_LT(int k)

double

Probability of getting less than 𝑘 successes in 𝑛 draws from a population of size 𝑁 with 𝐾 successes: P(X < k)

P_LTE(int k)

double

Probability of getting less than or exactly 𝑘 successes in 𝑛 draws from a population of size 𝑁 with 𝐾 successes: P(X ≤ k)

P_HT(int k)

double

Probability of getting more than 𝑘 successes in 𝑛 draws from a population of size 𝑁 with 𝐾 successes: P(X > k) = P(X ≤ k)

P_HTE(int k)

double

Probability of getting more than or exactly 𝑘 successes in 𝑛 draws from a population of size 𝑁 with 𝐾 successes: P(X ≥ k) = P(X < k)

Example

//Example: Suppose you have a jar containing 15 marbles: 10 red marbles 
//(successes) and 5 blue marbles (failures). You draw 5 marbles without 
//replacement and want to find the probability of drawing exactly 3 red marbles
int K = 10; //4 successful items (red marbles)
int N = 15; //total population size
int n = 5; //sample size of 5
Hypergeometric X = Hypergeometric(K, N, n);
std::cout << X.P(3) << std::endl; //0.3996

Good to know: k cannot be negative and has a max value of min(n, K).

Last updated