• PHP Video Tutorials

PHP - Stats Rand Gen f() Function



Definition and Usage

The stats_rand_gen_f() function can generate a random deviate from the F distribution.

Syntax

  float stats_rand_gen_f( float $dfn, float $dfd )

Parameters

Sr.No Parameter Description
1

dfn

The degrees of freedom in the numerator

2

dfd

The degrees of freedom in the denominator

Return Values

The stats_rand_gen_f() function can generate a random deviate from the F (variance ratio) distribution with a "dfn" degree of freedom in the numerator, and "dfd" degrees of freedom in the denominator. This function can generate a ratio of chi-square variates.

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 F distribution.

<?php
   var_dump(is_float(stats_rand_gen_f(3, 2)));
?>

Output

This will produce following result −

bool(true)

Example

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

<?php
   // error cases
   var_dump(stats_rand_gen_f(-0.1, 2));    // dfn < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_f(): Degrees of freedom nonpositive. DFN value: -1.000000E-1 DFD value: 2.000000E+0

bool(false)

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_rand_gen_f(3, -0.1));    // dfr < 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_f(): Degrees of freedom nonpositive. DFN value: 3.000000E+0 DFD value: -1.000000E-1

bool(false)
Advertisements