Boost: Chi-Squared distribution#
The following functions return the pdf, cdf, qtf or boost class of the chi-squared distribution with \(n > 0\) degrees of freedom and the support interval \((0,+\infty)\).
See also Wikipedia [1240], MathWorld [869], BoostMath [59], Ehrhardt [309] (3.9.6)
- Ctx.chi_squared_pdf(x, a=0, b=1)#
where
CtxisMath53orCtxBoost.Returns \(\text{pdf}(x)\), the value of the probability density function (Pdf) of the chi-squared distribution:
\[\text{pdf}(x) = f_{\chi^2}\left(x, n\right) = \frac{1}{2^{n/2} \Gamma(n/2)} x^{(n-2)/2}e^{-x/2}.\]The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("ChiSquaredPdf(x, a, b): ", ChiSquaredPdf(x, a, b)) >>> print ("dist_chi_squared(a, b).pdf(x): ", dist_chi_squared(a, b).pdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.chi_squared_cdf(x, a=0, b=1)#
where
CtxisMath53orCtxBoost.Returns \(\text{cdf}(x)\), the value of the cumulative distribution function (Cdf) of the chi-squared distribution:
\[\text{cdf}(x) = F_{\chi^2}\left(x, n\right) = P(n/2, x/2).\]Here \(P(\cdot)\) denotes the lower regularized incomplete gamma function (RealGammaP).
The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; x = 0.6; >>> print ("ChiSquaredCdf(x, a, b): ", ChiSquaredCdf(x, a, b)) >>> print ("dist_chi_squared(a, b).cdf(x): ", dist_chi_squared(a, b).cdf(x)) 6.3563523462564525615615615614561356E+00
- Ctx.chi_squared_qtf(q, a=0, b=1)#
where
CtxisMath53orCtxBoost.Returns \(\text{qtf}(q)\), the value of the quantile function (Qtf) of the chi-squared distribution:
\[\text{qtf}(q) = 2 P^{-1}(n/2, q).\]Here \(P^{-1}(\cdot)\) denotes the inverse of the lower regularized incomplete gamma function (RealGammaPInv).
The following example shows both forms of the syntax:
>>> from mpfebnet import * >>> a = 0; b = 1; t = 0.3; q = 0.6; >>> print ("ChiSquaredQtf(q, a, b): ", ChiSquaredQtf(q, a, b)) >>> print ("dist_chi_squared(a, b).qtf(q): ", dist_chi_squared(a, b).qtf(q)) 6.3563523462564525615615615614561356E+00
- class ctx.dist_chi_squared(n)#
where
ctxisfpm,mpm,ipm,dec,gmporapm.The chi-squared distribution is a continuous probability distribution with \(n > 0\) degrees of freedom and the support interval \((0,+\infty)\). See also Wikipedia [1240], MathWorld [869], BoostMath [59], Witkovský [1615], R (Statistical System) [547].
See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.chdtr.html#scipy.special.chdtr
See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.chdtrc.html#scipy.special.chdtrc
See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.chdtri.html#scipy.special.chdtri
- dist_chi_squared.pdf(x)#
Returns \(\text{pdf}_X(x)\), the probability density function (pdf) of a random variable \(X\), following a chi-squared distribution:
\[\text{pdf}_X(x) = f_{\chi^2}\left(n, x\right) = \frac{1}{2^{n/2} \Gamma(n/2)} x^{(n-2)/2}e^{-x/2}.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print ("pdf: ", chi_squared(mu, sigma).pdf(x)) 6.3563523462564525615615615614561356E-20
- dist_chi_squared.cdf(x)#
Returns \(\text{cdf}_X(x)\), the cumulative distribution function (cdf) of a random variable \(X\), following a chi-squared distribution:
\[\text{cdf}_X(x) = F_{\chi^2}\left(x, n\right) = P(n/2, x/2).\]Here \(P(\cdot)\) and \(P^{-1}(\cdot)\) are the regularized gamma function and its functional inverse, respectively.
>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print ("cdf: ", chi_squared(mu, sigma).pdf(x)) 6.3563523462564525615615615614561356E-20
- dist_chi_squared.sf(x)#
Returns \(\text{sf}_X(x)\), the survival function (sf) of a random variable \(X\), following a chi-squared distribution:
\[\text{sf}_X(x) = 1-F_{\chi^2}\left(x, n\right) = Q(n/2, x/2).\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; x = 3; >>> print (" sf: ", chi_squared(mu, sigma).pdf(x)) sf: 6.3563523462564525615615615614561356E-20
- dist_chi_squared.qtf(q)#
Returns \(\text{qtf}_X(x)\), the quantile function (qtf) of a random variable \(X\), following a chi-squared distribution:
\[\text{qtf}_X(q) = 2 P^{-1}(n/2, q).\]Here \(P(\cdot)\) and \(P^{-1}(\cdot)\) are the regularized gamma function and its functional inverse, respectively.
>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; q = 0.3; >>> print ("qtf: ", chi_squared(mu, sigma).qtf(q)) qtf: 6.3563523462564525615615615614561356E+00
- dist_chi_squared.isf(q)#
Returns \(\text{isf}_X(q)\), the inverse survival function (isf) of a random variable \(X\), following a chi-squared distribution:
\[\text{isf}_X(q) = 2 Q^{-1}(n/2, q).\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; q = 0.3; >>> print ("isf: ", chi_squared(mu, sigma).isf(q)) 6.3563523462564525615615615614561356E+00
- dist_chi_squared.c_x(t)#
Returns \(C_X(t)\), the characteristic function of a random variable \(X\), following a chi-squared distribution:
\[C_X(t) = (1-2it)^{-n/2}.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_chi_squared.m_x(t)#
Returns \(M_X(t)\), the moment generating function of a random variable \(X\), following a chi-squared distribution:
\[M_X(t) = (1-2t)^{-n/2}, \quad t \in \left(-\infty, \tfrac{1}{2}\right).\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; >>> print ("c_x: ", chi_squared(mu, sigma).c_x(t)) 6.3563523462564525615615615614561356E+00
- dist_chi_squared.k_x(t, k=0)#
Returns \(K_X(t)\), the cumulant generating function, and its \(j^{\text{th}}\) derivatives, \(K_X^{(j)}(t), j = 1 \ldots k\), of a random variable \(X\), following a chi-squared distribution:
\[K_X(t) = - \frac{n}{2} \log(1-2t), \quad t \in \left(-\infty, \tfrac{1}{2}\right),\]\[K_X^{(j)}(t) = \frac{2^{j-1}(j-1)!}{(1-2t)^j} n .\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; t = 0.3; k = 6; >>> print ("c_x: ", chi_squared(mu, sigma).k_x(t, k)) 6.3563523462564525615615615614561356E+00
- dist_chi_squared.moments(k)#
Returns the first \(j\) raw moments, \(\mu_j, j = 1 \ldots k\), of a random variable \(X\), following a chi-squared distribution: the moments are calculated from the cumulants.
>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; k = 6; >>> print ("saddlepoint: ", chi_squared(mu, sigma).moments(k)) 6.3563523462564525615615615614561356E+00
- dist_chi_squared.cumulants(k)#
Returns the first \(j\) cumulants, \(\kappa_j, j = 1 \ldots k\), of a random variable \(X\), following a chi-squared distribution:
\[\kappa_{r+1} = 2^r r! n.\]>>> from mpfunlab import * >>> mp.dps = 30 >>> mu = 0; sigma = 1; k = 6; >>> print ("saddlepoint: ", chi_squared(mu, sigma).cumulants(k)) 6.3563523462564525615615615614561356E+00
Recurrences: Central Chi-square
- ctx.chi_squared_recurrence(x, n, lambda)#
where
ctxisfpm,mpm,ipm,dec,gmporapm.The following recurrence relations hold for the pdf and CDF:
\[f_{\chi^2}(n+2, x) = \frac{x}{n} f_{\chi^2}(n, x)\]\[F_{\chi^2}(n, x) - F_{\chi^2}(n+2, x) = 2f_{\chi^2}(n+2, x)\]
Approximations
- ctx.chi_squared_gp(x, n, results='cdf')#
where
ctxisfpm,mpm,ipm,dec,gmporapm.Calculates the pdf, cdf and sf from the characteristic function using the procedure of Gil-Pelaez (see gil_pelaez_pdf() and gil_pelaez_cdf()).
- ctx.chi_squared_ecf(x, f, results='cdf')#
where
ctxisipm,dec,mpm, orgmp.Calculates the Edgeworth approximation to the pdf, cdf and sf.
- ctx.chi_squared_ecf_inv(q, f, results='qtf')#
where
ctxisipm,dec,mpm, orgmp.Calculates the Cornish-Fisher approximation to the qtf and isf.
- ctx.chi_squared_spa(x, n, results='c')#
where
ctxisfpm,mpm,ipm,dec,gmporapm.Calculates the Luggannini-Rice saddlepoint approximation of the pdf, cdf and sf.
The solution \(\hat{s}(x)\) of the saddlepoint equation \(K_X^{(1)}(\hat{s}(x))=x\), of a random variable \(X\), following a non-central chi-squared distribution is given by:
\[\hat{s}(x) = -\frac{1}{4x} \left[n-2x+n \right], \quad x>0\]
- ctx.chi_squared_spa_inv(x, n, results='qtf')#
where
ctxisfpm,mpm,ipm,dec,gmporapm.Calculates the inverse Jensen saddlepoint approximation of the qtf and isf.