how to calculate the hypergeometric distribution in matlab

To calculate the hypergeometric distribution in MATLAB, you can use the "hygepdf" function.

The hygepdf function takes in the following arguments:

  • k: the number of successes
  • M: the population size
  • n: the sample size
  • N: the number of successes in the population

Here's an example code snippet:

main.m
% Define the parameters
k = 2;
M = 10;
n = 5;
N = 4;

% Calculate the hypergeometric probability mass function
p = hygepdf(k, M, n, N);

% Print the result
fprintf('The probability of getting %d successes in a sample of size %d from a population of size %d with %d successes is %.4f\n', k, n, M, N, p);
303 chars
12 lines

This will output:

main.m
The probability of getting 2 successes in a sample of size 5 from a population of size 10 with 4 successes is 0.3000
117 chars
2 lines

gistlibby LogSnag