• PHP Video Tutorials

PHP - Stats Dens Laplace() Function



Definition and Usage

The stats_dens_laplace() function is a probability density function of the Laplace distribution.

Syntax

float stats_dens_laplace( 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 shape parameter of the distribution

Return Values

The stats_dens_laplace() function can return the probability density at x, where the random variable can follow the Laplace distribution of which the location parameter is ave and the scale parameter is stdev, 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_laplace($x, 1, 2), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.055783)
  float(0.071626)
  float(0.09197)
  float(0.118092)
  float(0.151633)
  float(0.1947)
  float(0.25)
  float(0.1947)
  float(0.151633)

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_laplace(0, $ave, 2), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.09197)
  float(0.118092)
  float(0.151633)
  float(0.1947)
  float(0.25)
  float(0.1947)
  float(0.151633)
  float(0.118092)
  float(0.09197)

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_laplace(0, 1, $stdev), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.135335)
  float(0.18394)
  float(0.171139)
  float(0.151633)

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_laplace(0, 1, 0));  // stdev == 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_dens_laplace(): stdev == 0.0

bool(false)
Advertisements