We now have a youtube channel. Subscribe!

PHP | stats_cdf_binomial() Function

PHP stats_cdf_binomial() 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_cdf_binomial() Function.

The built-in stats_cdf_binomial() function in PHP is used to calculate any one parameter of the binomial distribution given values for the others.

Syntax

Following below is the syntax to use this function -

float stats_cdf_binomial ( float $par1, float $par2, float $par3, int $which )


Parameter Details

Sr.NoParameterDescription
1

par1

The first parameter

2

par2

The second parameter

3

par3

The third parameter

4

which

The flag to determine what to be calculated


Return Value

This PHP function returns the cumulative distribution function, x, n, or p, determined by which. The kind of the return value and the parameters (par1, par2, and par3) are determined by which.

The following table list the return value and parameters by which.

  • CDF denotes cumulative distribution function.
  • x denotes the number of successes.
  • n denotes the number of trials.
  • p denotes the success rate for each trial.

whichReturn valuepar1par2par3
1CDFxnp
2xCDFnp
3nxCDFp
4pxCDFn

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

In the following example below, when which = 1, calculate P from (S, XN, PR).

  • P here is the cumulative from 0 to S of the binomial distribution. Input range: [0, 1].
  • S is the number of successes observed. Input range: [0, XN].
  • XN is the number of binomial trials. Input range: (0, +infinity).
  • PR is the probability of success in each of the binomial trial. Input range: (0, 1).

<?php
   // which = 1 : calculate P from (S, XN, PR)
   var_dump(round(stats_cdf_binomial(1, 3, 0.7, 1), 6));
?>

Output

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

float(0.216)

Example2

In the following example below, when which = 2, calculate S from (P, XN, PR).

  • P here is the cumulative from 0 to S of the binomial. Input range: [0, 1].
  • S is the number of successes observed. Input range: [0, XN].
  • XN is the number of binomial trials. Input range: (0, +infinity).
  • PR is the probability of success in each of the binomial trial. Input range: (0, 1).

<?php
   // which = 2 : calculate S from (P, XN, PR)
   var_dump(round(stats_cdf_binomial(0.216, 3, 0.7, 2), 6));
?>

Output

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

float(1)

Example3

In the following example below, when which = 3, calculate XN from (P, S, PR).

  • P is the cumulative from 0 to S of the binomial distribution. Input range: [0, 1].
  • S is the number of successes observed. Input range: [0, XN].
  • XN is the number of binomial trials. Input range: (0, +infinity).
  • PR is the probability of success in each of the binomial trial. Input range: (0, 1).

<?php
   // which = 3 : calculate XN from (P, S, PR)
   var_dump(round(stats_cdf_binomial(0.216, 1, 0.7, 3), 6));
?>

Output

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

float(3)

Example4

In the following example below, when which = 4, calculate PR from (P, S, XN).

  • P here is the cumulative from 0 to S of the binomial distribution. Input range: [0, 1].
  • S is the number of successes observed. Input range: [0, XN].
  • XN is the number of binomial trials. Input range: (0, +infinity).
  • PR is the probability of success in each of the binomial trial. Input range: (0, 1).

<?php
   // which = 4 : calculate PR from (P, S, XN)
   var_dump(round(stats_cdf_binomial(0.216, 1, 3, 4), 6));
?>

Output

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

float(0.7)

Example5

Following is an error case. In the following example below which<1, warning message is displayed in logs.

<?php
   var_dump(stats_cdf_binomial(1, 3, 0.7, 0));      // which < 1
?>

Output

The above code will produce the following result and a warning in logs PHP Warning: stats_cdf_binomial(): fourth parameter ought to be in the 1..4 range.

bool(false)

Example6

Following is an error case. In the following example below which>4, warning message is displayed in logs.

<?php
   var_dump(stats_cdf_binomial(1, 3, 0.7, 5));     // which > 4
?>

Output

The above code will produce the following result and a warning in logs PHP Warning: stats_cdf_binomial(): fourth parameter ought to be in the 1..4 range.

bool(false)


Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP stats_cdf_cauchy() Function.

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.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain