• PHP Video Tutorials

PHP - Stats CDF Noncentral chisquare() Function



Definition and Usage

The stats_cdf_noncentral_chisquare() function can calculate any one parameter of non-central chi-square distribution given values for the others.

Syntax

float stats_cdf_noncentral_chisquare( float $par1, float $par2, float $par3, int $which )

Parameters

Sr.No Parameter Description
1

par1

The first parameter

2

par2

The second parameter

3

par3

The third parameter

4

which

The flag to determine what to be calculated

Return Values

The stats_cdf_noncentral_chisquare() function can return the cumulative distribution function, its inverse, or one of its parameters of non-central chi-square distribution. The kind of return value and parameters (par1, par2, and par3) have determined by which.

Return value and parameters

The following table lists the return value and parameters by which.

  • CDF denotes cumulative distribution function.

  • x denotes the number of failure.

  • k denotes the number of success.

  • lambda denotes the success rate for each trial.

which Return value par1 par2 par3
1 CDF x k lambda
2 x CDF k lambda
3 k x CDF lambda
4 lambda x CDF k

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 when which=1, calculate P from (X, DF, PNONC).

  • P is the integral from 0 to X of the non-central chi-square distribution.

  • X is the upper limit of integration of the non-central chi-square distribution.

  • DF is the degrees of freedom of the non-central chi-square distribution.

  • PNONC is the non-centrality parameter of the non-central chi-square distribution.

<?php
   // which = 1 : calculate P from (X, DF, PNONC)
   var_dump(round(stats_cdf_noncentral_chisquare(4, 2, 3, 1), 6));
?>

Output

This will produce following result −

float(0.493562)

Example

In the following example when which=2, calculate X from (P, DF, PNONC).

  • P is the integral from 0 to X of the non-central chi-square distribution.

  • X is the upper limit of integration of the non-central chi-square distribution.

  • DF is the degrees of freedom of the non-central chi-square distribution.

  • PNONC is the non-centrality parameter of the non-central chi-square distribution.

<?php
   // which = 2 : calculate X from (P, DF, PNONC)
   var_dump(round(stats_cdf_noncentral_chisquare(0.493562417, 2, 3, 2), 6));
?>

Output

This will produce following result −

float(4)

Example

In the following example when which=3, calculate DF from (P, X, PNONC).

  • P is the integral from 0 to X of the non-central chi-square distribution.

  • X is the upper limit of integration of the non-central chi-square distribution.

  • DF is the degrees of freedom of the non-central chi-square distribution.

  • PNONC is the non-centrality parameter of the non-central chi-square distribution.

<?php
   // which = 3 : calculate DF from (P, X, PNONC)
   var_dump(round(stats_cdf_noncentral_chisquare(0.493562417, 4, 3, 3), 6));
?>

Output

This will produce following result −

float(2)

Example

In the following example when which=4, calculate PNONC from (P, X, DF).

  • P is the integral from 0 to X of the non-central chi-square distribution.

  • X is the upper limit of integration of the non-central chi-square distribution.

  • DF is the degrees of freedom of the non-central chi-square distribution.

  • PNONC is the non-centrality parameter of the non-central chi-square distribution.

<?php
   // which = 4 : calculate PNONC from (P, X, DF)
   var_dump(round(stats_cdf_noncentral_chisquare(0.493562417, 4, 2, 4), 6));
?>

Output

This will produce following result −

float(3)

Example

Following is an error case. In the following example which<1, warning is displayed in logs.

<?php
   var_dump(stats_cdf_noncentral_chisquare(4, 2, 3, 0));       // which < 1
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_cdf_noncentral_chisquare(): Fourth parameter should be in the 1..4 range

bool(false)

Example

Following is an error case. In the following example which>4, warning is displayed in logs.

<?php
   var_dump(stats_cdf_noncentral_chisquare(4, 2, 3, 5));       // which > 4
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_cdf_noncentral_chisquare(): Fourth parameter should be in the 1..4 range

bool(false)
Advertisements