Chi-squared Distribution

Table of contents


Density Function

The density function of the Chi-squared distribution:

\[f(x; k) = \dfrac{x^{k/2 - 1} \exp(-x/2)}{ 2^{k/2} \Gamma(k/2)} \times \mathbf{1}[ x \geq 0]\]

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.dchisq(x: float, dof: float = 1.0, log: bool = False) float

Density function of the Chi-squared distribution.

Example

>>> pystats.dchisq(4.0, 5)
0.1439759107018347
Parameters
  • x (float) – A real-valued input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

The density function evaluated at x.

List Input

pystats.dchisq(x: List[float], dof: float = 1.0, log: bool = False) List[float]

Density function of the Chi-squared distribution.

Example

>>> pystats.dchisq([1.8, 0.7, 4.2], 4)
[0.18295634688326964, 0.12332041570077489, 0.12857924966563097]
Parameters
  • x (List[float]) – A standard list input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

A list of density values corresponding to the elements of x.


Cumulative Distribution Function

The cumulative distribution function (CDF) of the Chi-squared distribution:

\[F(x; k) = \int_0^x f(z; k) dz = \frac{\gamma(k/2,x/2)}{\Gamma (k/2)}\]

where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.pchisq(p: float, dof: float = 1.0, log: bool = False) float

Distribution function of the Chi-squared distribution.

Example

>>> pystats.pchisq(4.0, 5)
0.45058404864721946
Parameters
  • p (float) – A real-valued input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

The cumulative distribution function evaluated at p.

List Input

pystats.pchisq(p: List[float], dof: float = 1.0, log: bool = False) List[float]

Distribution function of the Chi-squared distribution.

Example

>>> pystats.pchisq([1.8, 0.7, 4.2], 4)
[0.22751764649286174, 0.048671078879736845, 0.620385072415756]
Parameters
  • p (List[float]) – A standard list input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

  • log (bool) – Return the log-density or the true form.

Returns

A list of CDF values corresponding to the elements of p.


Quantile Function

The quantile function of the Chi-squared distribution:

\[q(p; k) = \inf \left\{ x : p \leq \gamma(k/2,x/2) / \Gamma (k/2) \right\}\]

where \(\Gamma(\cdot)\) denotes the gamma function and \(\gamma(\cdot, \cdot)\) denotes the incomplete gamma function.

Methods for scalar input, as well as for list input, are listed below.

Scalar Input

pystats.qchisq(q: float, dof: float = 1.0) float

Quantile function of the Chi-squared distribution.

Example

>>> pystats.qchisq(0.5, 5)
4.351460191095529
Parameters
  • q (float) – A real-valued input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

Returns

The quantile function evaluated at q.

List Input

pystats.qchisq(q: List[float], dof: float = 1.0) List[float]

Quantile function of the Chi-squared distribution.

Example

>>> pystats.qchisq([1.8, 0.7, 4.2], 4)
[2.194698421406983, 3.356693980033322, 5.988616694004245]
Parameters
  • q (List[float]) – A standard list input.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

Returns

A list of quantiles values corresponding to the elements of q.


Random Sampling

Scalar Output

pystats.rchisq(dof: float = 1.0) float

Random sampling function for the Chi-squared distribution.

Example

>>> pystats.rchisq(dof=5)
7.088454619471778
Parameters

dof (float) – The degrees of freedom parameter, a real-valued input.

Returns

A pseudo-random draw from the Chi-squared distribution.

List Output

pystats.rchisq(n: int, dof: float = 1.0) List[float]

Random sampling function for the Chi-squared distribution.

Example

>>> pystats.rchisq(5, 5)
[2.3284093401299866, 9.215161276152928, 6.904990781549569, 8.257146493760509, 4.299710184814277]
Parameters
  • n (int) – The number of output values.

  • dof (float) – The degrees of freedom parameter, a real-valued input.

Returns

A list of pseudo-random draws from the Chi-squared distribution.