• PHP Video Tutorials

PHP - Stats Dens t() Function



Definition and Usage

The stats_dens_t() function is a probability density function of the t-distribution.

Syntax

  float stats_dens_t( 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_t() function can return the probability density at x, where the random variable can follow the t-distribution in which the degree of freedom is dfr, 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 at each x.

<?php
   // check foreach x
   foreach (range(-1, 1, 0.5) as $x) {
      var_dump(round(stats_dens_t($x, 1), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.159155)
  float(0.254648)
  float(0.31831)
  float(0.254648)
  float(0.159155)

Example

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

<?php
   // check foreach dfr
   foreach (range(0.5, 2, 0.5) as $dfr) {
      var_dump(round(stats_dens_t(0, $dfr), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.269676)
  float(0.31831)
  float(0.340735)
  float(0.353553)

Example

Following is an error case. In the following example, we pass dfr == 0. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_dens_t(1, 0));   // dfr == 0
?>

Output

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

bool(false)
Advertisements