• PHP Video Tutorials

PHP - Stats CDF Exponential() Function



Definition and Usage

The stats_cdf_exponential() function calculates any one parameter of exponential distribution given values for the others.

Syntax

float stats_cdf_exponential ( float $par1, float $par2, int $which )

Parameters

Sr.No Parameter Description
1

par1

The first parameter

2

par2

The second parameter

3

which

The flag to determine what to be calculated

Return Values

This function returns the cumulative distribution function, its inverse, or one of its parameters, of the exponential distribution. The kind of the return value and parameters (par1 and par2) 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 value of the random variable.

  • lambda denotes the rate parameter of the exponential distribution.

which Return value par1 par2
1 CDF x lambda
2 x CDF lambda
3 lambda x CDF

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 (X, SCALE).

  • P is the probability of an event (0 < p < 1)) .

  • X is the random variable.

  • SCALE is the scale parameter.

<?php
   // which = 1 : calculate P from (X, SCALE)
   var_dump(round(stats_cdf_exponential(1, 2, 1), 6));
?>

Output

This will produce following result −

float(0.393469)

Example

In the following example when which=2, calculate X from (P, SCALE).

  • P is the probability of an event (0 < p < 1)) .

  • X is the random variable.

  • SCALE is the scale parameter.

<?php
   // which = 2 : calculate X from (P, SCALE)
   var_dump(round(stats_cdf_exponential(0.39346934, 2, 2), 6));
?>

Output

This will produce following result −

float(1)

Example

In the following example when which=3, calculate SCALE from (P, X) .

  • P is the probability of an event (0 < p < 1)) .

  • X is the random variable.

  • SCALE is the scale parameter.

<?php
   // which = 3 : calculate SCALE from (P, X)
   var_dump(round(stats_cdf_exponential(0.39346934, 1, 3), 6));
?>

Output

This will produce following result −

float(2)

Example

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

<?php
var_dump(stats_cdf_exponential(1, 2, 0)); // which < 1
?>

Output

This will produce following result and a warning in logs stats_cdf_exponential(): Third parameter should be in the 1..3 range

bool(false)

Example

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

<?php
var_dump(stats_cdf_exponential(4, 3, 4));   // which > 3
?>

Output

This will produce following result and a warning in logs stats_cdf_exponential(): Third parameter should be in the 1..3 range

bool(false)
Advertisements