• PHP Video Tutorials

PHP - Stats Dens Chisquare() Function



Definition and Usage

The stats_dens_chisquare() function is a probability density function of the chi-square distribution.

Syntax

float stats_dens_chisquare( float $x, float $dfr )

Parameters

Sr.No Parameter Description
1

x

The value at which the probability density is calculated

2

dfr

The degree of freedom of the distribution

Return Values

The stats_dens_chisquare() function can return probability density at x, where the random variable can follow the chi-square distribution of which the degree of freedom is dfr, 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(0.5, 3, 0.5) as $x) {
      var_dump(round(stats_dens_chisquare($x, 3), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.219696)
  float(0.241971)
  float(0.230799)
  float(0.207554)
  float(0.180722)
  float(0.15418)

Example

In the following example, we compute probability density for each dfr.

<?php
   // check for each dfr
   foreach (range(0.5, 3, 0.5) as $dfr) {
      var_dump(round(stats_dens_chisquare(1, $dfr), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.140674)
  float(0.241971)
  float(0.294304)
  float(0.303265)
  float(0.281348)
  float(0.241971)
Advertisements