We now have a youtube channel. Subscribe!

# PHP | stats_dens_pmf_hypergeometric() Function

Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP stats_dens_pmf_hypergeometric() function.

The PHP stats_dens_pmf_hypergeometric() function is a Probability Mass Function of the hypergeometric distribution.

## Syntax

Following below is the syntax to use this function -

`float stats_dens_pmf_hypergeometric( float \$n1, float \$n2, float \$N1, float \$N2 )`

## Parameter Details

Sr.NoParameterDescription
1

n1

The number of success, at which the probability mass is calculated

2

n2

The number of failure of the distribution

3

N1

The number of success samples of the distribution

4

N2

The number of failure samples of the distribution

## Return Value

This built-in function returns the probability mass at n1, where the random variable can follow the hypergeometric distribution of which the number of failures is n2, number of success samples is N1, and the number of failure samples is N2, or false on failure.

## Dependencies

This built-in function was first introduced in statistics extension (PHP version 4.0.0 and PEAR v1.4.0). In this tutorial guide, we used the latest release of stats-2.0.3 (PHP v7.0.0 or newer and PEAR version 1.4.0 or newer).

### Example1

The following example below computes the probability mass for each n1 -

```<?php
// check for each n1
foreach (range(0, 3) as \$n1) {
var_dump(stats_dens_pmf_hypergeometric(\$n1, 1, 2, 3));
echo "<br>";
}
?>```

#### Output

When the above code is executed, it will produce the following result -

```float(0.6)
float(0.6)
float(0.3)
float(0)```

### Example2

The following example below computes the probability mass for each n2 -

```<?php
// check for each n2
foreach (range(0, 3) as \$n2) {
var_dump(stats_dens_pmf_hypergeometric(1, \$n2, 2, 3));
echo "<br>";
}
?>```

#### Output

When the above code is executed, it will produce the following output -

```float(0.4)
float(0.6)
float(0.6)
float(0.4)```

### Example3

The following example below computes the probability mass for each N1 -

```<?php
// check for each N1
foreach (range(0, 3) as \$N1) {
var_dump(stats_dens_pmf_hypergeometric(1, 1, \$N1, 3));
echo "<br>";
}
?>```

#### Output

When the above code is executed, it will produce the following output -

```float(0)
float(0.5)
float(0.6)
float(0.6)```

### Example4

The following example below computes the probability mass for each N2 -

```<?php
// check for each N2
foreach (range(1, 3) as \$N2) {
var_dump(round(stats_dens_pmf_hypergeometric(1, 1, 2, \$N2), 6));
echo "<br>";
}
?>```

#### Output

When the above code is executed, it will produce the following result -

```float(0.666667)
float(0.666667)
float(0.6)```

### Example5

The following below is an error case. In the following example, we passed n1 + n2 > N1 + N2. A warning is shown in logs -

```<?php
// error cases
var_dump(stats_dens_pmf_hypergeometric(1, 3, 1, 2)); // n1 + n2 > N1 + N2
?>```

#### Output

The above code will produce the following result and a warning in logs PHP Warning: stats_dens_pmf_hypergeometric(): possible division by zero - n1 + n2 >= N1 + N2

`float(NAN)`

Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we will be studying about the built-in stats_dens_pmf_negative_binomial() Function in PHP.

Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.