PHP - Stats Dens Cauchy() Function
Definition and Usage
The stats_dens_cauchy() function is a probability density function of Cauchy distribution.
Syntax
float stats_dens_cauchy( float $x, float $ave, float $stdev )
Parameters
| Sr.No | Parameter | Description |
|---|---|---|
| 1 | x |
The value at which the probability density is calculated |
| 2 | ave |
The location parameter of the distribution |
| 3 | stdev |
The scale parameter of the distribution |
Return Values
The stats_dens_cauchy() function can return the probability density at x, where the random variable can follow Cauchy distribution whose location and scale are ave and stdev, respectively, or false on failure.
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, we compute probability density for each x.
<?php
// check for each x
foreach (range(-2, 2, 0.5) as $x) {
var_dump(round(stats_dens_cauchy($x, 2, 3), 6));
echo "<br>";
}
?>
Output
This will produce following result −
float(0.038197) float(0.044938) float(0.053052) float(0.062618) float(0.073456) float(0.084883) float(0.095493) float(0.103236) float(0.106103)
Example
In the following example, we compute probability density for each ave.
<?php
// check for each ave
foreach (range(-2, 2, 0.5) as $ave) {
var_dump(round(stats_dens_cauchy(1, $ave, 3), 6));
echo "<br>";
}
?>
Output
This will produce following result −
float(0.053052) float(0.062618) float(0.073456) float(0.084883) float(0.095493) float(0.103236) float(0.106103) float(0.103236) float(0.095493)
Example
In the following example, we compute probability density for each stdev.
<?php
// check for each stdev
foreach (range(0.5, 2, 0.5) as $stdev) {
var_dump(round(stats_dens_cauchy(1, 2, $stdev), 6));
echo "<br>";
}
?>
Output
This will produce following result −
float(0.127324) float(0.159155) float(0.146912) float(0.127324)
Example
Following is an error case. In the following example, we pass stdev == 0. A warning is displayed in logs.
<?php // error cases var_dump(stats_dens_cauchy(1, 2, 0)); // stdev == 0 ?>
Output
This will produce following result and a warning in logs PHP Warning: stats_dens_cauchy(): stdev is 0.0
bool(false)