BETA_DIST
Updated 2024-02-13 20:41:09.970000
Syntax
SELECT [westclintech].[wct].[BETA_DIST](
<@X, float,>
,<@Alpha, float,>
,<@Beta, float,>
,<@Cumulative, bit,>
,<@A, float,>
,<@B, float,>)
Description
Use the scalar function BETA_DIST to calculate the probability density function or cumulative distribution function of a beta distribution for x with shape parameters α and ß.
Arguments
@A
The lower bound of the interval for @X. @A must be of a type float or of a type that intrinsically converts to float.
@Cumulative
A bit value indicating whether the probability density function ( 'False') or the cumulative distribution function ('True') should be returned.
@B
The upper bound of the interval for @X. @B must be of a type float or of a type that intrinsically converts to float.
@Beta
The second shape parameter for the distribution. @Beta must be of a type float or of a type that intrinsically converts to float.
@Alpha
The first shape parameter for the distribution. @Alpha must be of a type float or of a type that intrinsically converts to float.
@X
The value of interest. @X must be of a type float or of type that intrinsically converts to float.
Return Type
float
Remarks
@A ≤ @X ≤ @B.
@Alpha > 0.
@Beta > 0.
If @A is NULL then @A = 0.
If @B is NULL then @B = 1.
Examples
In this example we calculate the beta cumulative distribution function for x = 2, alpha = 8, beta = 10, with location parameters 8, 10.
SELECT wct.BETA_DIST( 2, --@X
8, --@Alpha
10, --@Beta
'True', --@Cumulative
1, --@A
3 --@B
) as CDF;
This produces the following result.
{"columns":[{"field":"CDF","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"CDF":"0.685470581054688"}]}
Using the same data we calculate the beta probability density function.
SELECT wct.BETA_DIST( 2, --@X
8, --@Alpha
10, --@Beta
'False', --@Cumulative
1, --@A
3 --@B
) as PDF;
This produces the following result.
{"columns":[{"field":"PDF","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"PDF":"1.4837646484375"}]}
This example demonstrates the recurrence relationship 26.5.10 from Abramowitz & Stegun .
DECLARE @x as float = 0.75;
DECLARE @Alpha as float = 4;
DECLARE @Beta as float = 10;
SELECT wct.BETA_DIST(@x, @alpha, @beta, 1, NULL, NULL) as cdf,
@x * wct.BETA_DIST(@x, @alpha - 1, @beta, 1, NULL, NULL) + (1 - @x)
* wct.BETA_DIST(@x, @alpha, @beta - 1, 1, NULL, NULL) as cdf2;
This produces the following result.
{"columns":[{"field":"cdf","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"cdf2","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"cdf":"0.999873876571655","cdf2":"0.999873876571655"}]}
In this example we compare the results returned by the function to the results returned by integration.
DECLARE @x as float = 0.75
DECLARE @Alpha as float = 4
DECLARE @Beta as float = 10
SELECT
wct.BETA_DIST(@x,@alpha,@beta,1,NULL,NULL) as cdf
,wct.QUADTS('SELECT POWER(@x,' + Cast(@alpha-1 as varchar(max)) + ')*POWER(1-@x,' + cast(@beta-1 as varchar(max)) + ')','@x',0,@x)/wct.BETA(@alpha,@beta) as [Integral];
This produces the following result.
{"columns":[{"field":"cdf","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"Integral","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"cdf":"0.999873876571655","Integral":"0.999873876571659"}]}
See Also
BETAI - Incomplete beta function
BETAINV - Inverse of the beta distribution
BETAPDF - Probability density function of the beta distribution