• PHP Video Tutorials

PHP - Stats Rand Gen Noncentral Chisquare() Function



Definition and Usage

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

Syntax

  float stats_rand_gen_noncentral_chisquare( float $df, float $xnonc )

Parameters

Sr.No Parameter Description
1

df

The degrees of freedoms

2

xnonc

The non-centrality parameter

Return Values

The stats_rand_gen_noncentral_chisquare() function can return a random deviate from the non-central chi-square distribution with a degree of freedom, df, and non-centrality parameter, xnonc.

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 generate a random deviate from the non-central chi-square distribution with a degree of freedom, 2, and non-centrality parameter, 3.

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

Output

This will produce following result −

bool(true)

Example

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

<?php
   // error cases
   var_dump(stats_rand_gen_noncentral_chisquare(0.9, 3));  // df < 1
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_noncentral_chisquare(): df < 1 or xnonc < 0. df value : 9.000000E-1 xnonc value : 3.000000E+0

bool(false)

Example

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

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

Output

This will produce following result and a warning in logs PHP Warning: stats_rand_gen_noncentral_chisquare(): df < 1 or xnonc < 0. df value : 2.000000E+0 xnonc value : -1.000000E-1

bool(false)
Advertisements