SQL Server BETA.DIST function

BETA_DIST

Updated: 31 July 2015

Use BETA_DIST to calculate the probability density function or cumulative distribution function of a beta distribution for x with shape parameters a and ß.
Syntax
SELECT [wct].[BETA_DIST](
<@X, float,>
,<@Alpha, float,>
,<@Beta, float,>
,<@Cumulative, bit,>
,<@A, float,>
,<@B, float,>)

Arguments
@X
The value of interest. @X must be of a type float or of 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.
@Beta
The second shape parameter for the distribution. @Beta 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.
@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.
@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.
Return Type
float
Remarks
·         @A = @X = @B
·         @Alpha > 0
·         @Beta > 0
·         If @A = @B Then NULL is returned
·         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

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.

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.

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.