maTH
  • 👋Welcome!
  • 🗿Installation
  • Reference
    • 😱Mathematical operations
      • add
      • pascal
      • factorial
      • factorialL
      • GCD
      • LCM
      • pow
      • permutations
      • combinations
      • combinationsWithRep
      • subtract
      • multiply
      • divide
      • sin
      • cos
      • ln
      • log
      • radToDeg
      • degToRad
      • mod
      • abs
      • floor
      • ceil
      • root
      • exp
      • tan
      • arcsin
      • arccos
      • arctan
      • sinh
      • cosh
      • round
    • 🥶Statistics
      • Binomial
      • Poisson
      • Geometric
      • Pascal
      • Hypergeometric
      • Exponential
      • Uniform
    • 🥵Data structures
      • Stack
      • Queue
      • LinkedList
    • 🤓Algorithms
      • Bubble sort
      • Insertion sort
      • Selection sort
      • Merge sort
      • Quicksort
      • Heap sort
      • Count sort
      • Bucket sort
      • Radix sort
    • 😳Constants
Powered by GitBook
On this page
  • Create a new Hypergeometric distribution
  • Example
  1. Reference
  2. Statistics

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
Hypergeometric X = Hypergeometric(5, 15, 2);
std::cout << X.P(-1) << std::endl; //Error: Number of successes in sample cannot be less than 0 or more than the sample size or more than the number of successes in population.

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

PreviousPascalNextExponential

Last updated 11 months ago

🥶