• PHP Video Tutorials

PHP - Stats Dens Logistic() Function



Definition and Usage

The stats_dens_logistic() function is a probability density function of the logistic distribution.

Syntax

float stats_dens_logistic( 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_logistic() function can return the probability density at x, where the random variable can follow the logistic distribution of which the location parameter is ave and the scale parameter is stdev, or false for 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_logistic($x, 2, 3), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.05503)
  float(0.060357)
  float(0.065537)
  float(0.070389)
  float(0.074719)
  float(0.078335)
  float(0.081061)
  float(0.082757)
  float(0.083333)

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_logistic(1, $ave, 3), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.065537)
  float(0.070389)
  float(0.074719)
  float(0.078335)
  float(0.081061)
  float(0.082757)
  float(0.083333)
  float(0.082757)
  float(0.081061)

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

Output

This will produce following result −

  float(0.209987)
  float(0.196612)
  float(0.149438)
  float(0.117502)

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

Output

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

bool(false)
Advertisements