Logo

CHISQ_DIST

Updated 2023-11-02 21:06:18.793000

Syntax

SELECT [westclintech].[wct].[CHISQ_DIST](
  <@X, float,>
 ,<@Degrees_freedom, float,>
 ,<@Cumulative, bit,>)

Description

Use the scalar function CHISQ_DIST to calculate the probability density or the lower cumulative probability of a chi-squared distribution for x and a number of degrees of freedom.

Arguments

@Cumulative

A bit value indicating whether the probability density function ( 'False') or the cumulative distribution function ( 'True') should be returned.

@X

The value of interest to be evaluated. @X must be of a type float or of type that intrinsically converts to float.

@Degrees_freedom

The number of degrees freedom. @Degrees_freedom must be of a type float or of a type that intrinsically converts to float.

Return Type

float

Remarks

0 < @X.

0 < @Degrees_freedom.

Examples

In this example we calculate the chi-squared lower-tailed cumulative distribution function.

SELECT wct.CHISQ_DIST(   0.5,   --@X

                         1,     --@Degrees_freedom

                         'True' --@Cumulative

                     ) as CDF;

This produces the following result.

{"columns":[{"field":"CDF","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"CDF":"0.520499877813047"}]}

Using the same data we calculate the chi-squared probability density function.

SELECT wct.CHISQ_DIST(   0.5,    --@X

                         1,      --@Degrees_freedom

                         'False' --@Cumulative

                     ) as PDF;

This produces the following result.

{"columns":[{"field":"PDF","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"PDF":"0.439391289467723"}]}

The chi-squared distribution is a special case of the gamma distribution.

SELECT wct.CHISQ_DIST(x, df, 'True') as [Chi-squared],

       wct.GAMMAP(0.5 * df, 0.5 * x) as GammaP

FROM

(

    VALUES

        (42, 57)

) n (x, df);

This produces the following result.

{"columns":[{"field":"Chi-squared","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"GammaP","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"Chi-squared":"0.0684558390451818","GammaP":"0.0684558390451818"}]}

See Also

CHISQ_INV - Inverse of the chi-squared distribution

CHISQ_DIST_RT - Upper chi-squared distribution

CHISQ_INV_RT - Calculate the inverse of the right-tailed probability of a chi-squared distribution.

GAMMAP - lower regularized gamma function

GAMMALN - natural logarithm of the complete gamma function