PHP - Stats CDF Cauchy() Function
Definition and Usage
The stats_cdf_cauchy() function can calculate any one parameter of Cauchy distribution given values for the others.
Syntax
float stats_cdf_cauchy ( float $par1, float $par2, float $par3, int $which )
Parameters
| Sr.No | Parameter | Description |
|---|---|---|
| 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 the cumulative distribution function, its inverse, or one of its parameters, of the Cauchy distribution. 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 value of the random variable.
x0 denotes the location of the Cauchy distribution.
gamma denotes the scale parameter of the Cauchy distribution.
| which | Return value | par1 | par2 | par3 |
|---|---|---|---|---|
| 1 | CDF | x | x0 | gamma |
| 2 | x | CDF | x0 | gamma |
| 3 | x0 | x | CDF | gamma |
| 4 | gamma | x | CDF | x0 |
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, MEAN, SD).
P is the cumulation cauchy distribution. Input range: [0, 1] .
X is the value of the random variable.
MEAN of cauchy distribution.
SD is Standard Deviation.
<?php // which = 1 : calculate P from (X, MEAN, SD) var_dump(round(stats_cdf_cauchy(1, 2, 3, 1), 6)); ?>
Output
This will produce following result −
float(0.397584)
Example
In the following example when which=2, calculate X from (P, MEAN, SD).
P is the cumulation cauchy distribution. Input range: [0, 1] .
X is the value of the random variable.
MEAN of cauchy distribution.
SD is Standard Deviation.
<?php // which = 2 : calculate X from (P, MEAN, SD) var_dump(round(stats_cdf_cauchy(0.397583618, 2, 3, 2), 6)); ?>
Output
This will produce following result −
float(1)
Example
In the following example when which=3, calculate MEAN from (P, X, SD).
P is the cumulation cauchy distribution. Input range: [0, 1] .
X is the value of the random variable.
MEAN of cauchy distribution.
SD is Standard Deviation.
<?php // which = 3 : calculate MEAN from (P, X, SD) var_dump(round(stats_cdf_cauchy(0.397583618, 1, 3, 3), 6)); ?>
Output
This will produce following result −
float(2)
Example
In the following example when which=4, calculate SD from (P, X, MEAN).
P is the cumulation cauchy distribution. Input range: [0, 1] .
X is the value of the random variable.
MEAN of cauchy distribution.
SD is Standard Deviatio.
<?php // which = 4 : calculate SD from (P, X, MEAN) var_dump(round(stats_cdf_cauchy(0.397583618, 1, 2, 4), 6)); ?>
Output
This will produce following result −
float(0.3)
Example
Following is an error case. In the following example which<1, warning is displayed in logs.
<?php var_dump(stats_cdf_cauchy(1, 2, 3, 0)); // which < 1 ?>
Output
This will produce following result and a warning in logs PHP Warning: stats_cdf_cauchy(): 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.
<?php var_dump(stats_cdf_cauchy(1, 2, 3, 5)); // which > 4?> ?>
Output
This will produce following result and a warning in logs PHP Warning: stats_cdf_cauchy(): Fourth parameter should be in the 1..4 range
bool(false)