• PHP Video Tutorials

PHP - Stats Rand Gen Chisquare() Function



Definition and Usage

The stats_rand_gen_chisquare() function can generate a random deviate from the chi-square distribution.

Syntax

  float stats_rand_gen_chisquare( float $df )

Parameters

Sr.No Parameter Description
1

df

The degrees of freedom

Return Values

The stats_rand_gen_chisquare() function can return a random deviate from the chi-square distribution where the degrees of freedom are df.

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 random deviation from the chi-square distribution .

<?php
   var_dump(is_float(stats_rand_gen_chisquare(3)));
?>

Output

This will produce following result −

bool(true)

Example

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

<?php
   // error cases
   var_dump(stats_rand_gen_chisquare(-0.1));   // df < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_chisquare(): df <= 0.0. df : -1.000000E-1

bool(false)

Example

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

<?php
   // error cases
   var_dump(stats_rand_gen_chisquare(0));      // df == 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_chisquare(): df <= 0.0. df : 0.000000E+0

bool(false)
Advertisements