Hướng dẫn dùng binomial cdf trong PHP

Calculates any one parameter of the binomial
     distribution given values for the others.

                              Arguments

     WHICH --> Integer indicating which of the next four argument
               values is to be calculated from the others.
               Legal range: 1..4
               iwhich = 1 : Calculate P and Q from S,XN,PR and OMPR
               iwhich = 2 : Calculate S from P,Q,XN,PR and OMPR
               iwhich = 3 : Calculate XN from P,Q,S,PR and OMPR
               iwhich = 4 : Calculate PR and OMPR from P,Q,S and XN

     P <--> The cumulation from 0 to S of the binomial distribution.
            (Probablility of S or fewer successes in XN trials each
            with probability of success PR.)
            Input range: [0,1].

     Q <--> 1-P.
            Input range: [0, 1].
            P + Q = 1.0.

     S <--> The number of successes observed.
            Input range: [0, XN]
            Search range: [0, XN]

     XN  <--> The number of binomial trials.
              Input range: (0, +infinity).
              Search range: [1E-100, 1E100]

     PR  <--> The probability of success in each binomial trial.
              Input range: [0,1].
              Search range: [0,1]

     OMPR  <--> 1-PR
              Input range: [0,1].
              Search range: [0,1]
              PR + OMPR = 1.0

     STATUS <-- 0 if calculation completed correctly
               -I if input parameter number I is out of range
                1 if answer appears to be lower than lowest
                  search bound
                2 if answer appears to be higher than greatest
                  search bound
                3 if P + Q .ne. 1
                4 if PR + OMPR .ne. 1

     BOUND <-- Undefined if STATUS is 0

               Bound exceeded by parameter number I if STATUS
               is negative.

               Lower search bound if STATUS is 1.

               Upper search bound if STATUS is 2.



Definition and Usage

The stats_cdf_binomial() function can calculate any one parameter of binomial distribution given values for the others.

Syntax

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

Parameters

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 Values

Returns CDF, x, n, or p, determined by which. The kind of the return value and parameters (par1, par2, and par3) are determined by which.

Return value and parameters

The following table lists 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
1 CDF x n p
2 x CDF n p
3 n x CDF p
4 p x CDF n

Dependencies

This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial.

Example

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

  • P is the cumulation from 0 to S of the binomial distribution. Input range: [0, 1] .

  • S is number of successes observed. Input range: [0,XN].

  • XN is number of binomial trials. Input range: (0, +infinity).

  • PR is the probability of success in each binomial trial. Input range: (0, 1).

Output

This will produce following result −

float(0.216)

Example

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

  • P is the cumulation from 0 to S of the binomial distribution. Input range: [0, 1] .

  • S is number of successes observed. Input range: [0,XN].

  • XN is number of binomial trials. Input range: (0, +infinity).

  • PR is the probability of success in each binomial trial. Input range: (0, 1).

Output

This will produce following result −

float(1)

Example

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

  • P is the cumulation from 0 to S of the binomial distribution. Input range: [0, 1] .

  • S is number of successes observed. Input range: [0,XN].

  • XN is number of binomial trials. Input range: (0, +infinity).

  • PR is the probability of success in each binomial trial. Input range: (0, 1).

Output

This will produce following result −

float(3)

Example

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

  • P is the cumulation from 0 to S of the binomial distribution. Input range: [0, 1] .

  • S is number of successes observed. Input range: [0,XN].

  • XN is number of binomial trials. Input range: (0, +infinity).

  • PR is the probability of success in each binomial trial. Input range: (0, 1).

Output

This will produce following result −

float(0.7)

Example

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

Output

This will produce following result and a warning in logs PHP Warning: stats_cdf_binomial(): Fourth parameter should be in the 1..4 range

bool(false)

Example

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

 4
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_cdf_binomial(): Fourth parameter should be in the 1..4 range

bool(false)