Logo

BINOM_DIST_RANGE

Updated 2024-02-13 20:44:08.533000

Syntax

SELECT [westclintech].[wct].[BINOM_DIST_RANGE](
  <@Trials, int,>
 ,<@Probability_s, float,>
 ,<@Number_s, int,>
 ,<@Number_s2, int,>)

Description

Use the scalar function BINOM_DIST_RANGE to calculate the probability of a trial result using a binomial distribution.

Arguments

@Number_s2

The upper bound of the number of successes in @Trials. @Number_s2 must be of a type int or of a type that intrinsically converts to int.

@Number_s

The number of successes in @Trials. @Number_s must be of a type int or of a type that intrinsically converts to int.

@Probability_s

The probability of success in each trial. @Probability_s must be of a type float or of a type that intrinsically converts to float.

@Trials

The number of independent trials. @Trials must be of a type int or of type that intrinsically converts to int.

Return Type

float

Remarks

@Trials > 0.

0 ≤ @Probability_s ≤ 1.

0 ≤ @Number_s = @Trials

If NOT NULL then 0 ≤ @Number_s2 ≤ @Trials

Examples

Calculate the probability of having exactly 48 successes in 60 trials when the probability of success is 75%.

SELECT wct.BINOM_DIST_RANGE(   60,   --@Trials

                               0.75, --@Probability_s

                               48,   --@Number_s

                               NULL  --@Number_s2

                           ) as BINOM_DIST_RANGE;

This produces the following result.

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

This is actually no different than calculating the probability mass function of the binomial distribution.

SELECT wct.BINOMDIST(48, 60, 0.75, 'False') as PMF;

This produces the following result.

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

Let's look at another example where we calculate the probability of having exactly 500 successes in 1,000 trial where the probability of success is 50%.

SELECT wct.BINOM_DIST_RANGE(   1000, --@Trials

                               0.50, --@Probability_s

                               500,  --@Number_s

                               NULL  --@Number_s2

                           ) as BINOM_DIST_RANGE;

This produces the following result.

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

It might be far more useful, however, to calculate the probability of having between 450 and 550 successes.

SELECT wct.BINOM_DIST_RANGE(   1000, --@Trials

                               0.50, --@Probability_s

                               450,  --@Number_s

                               550   --@Number_s2

                           ) as BINOM_DIST_RANGE;

This produces the following result.

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

In this example we bucket the results into 20 equal groups using the XLeratorDB SeriesInt function.

SELECT seriesvalue - 49 as lb,

       seriesvalue as ub,

       wct.BINOM_DIST_RANGE(1000, 0.50, seriesvalue - 49, seriesvalue) as p

FROM wct.SeriesInt(50, 1000, 50, NULL, NULL);

This produces the following result.

{"columns":[{"field":"lb","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"ub","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"p","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"lb":"1","ub":"50","p":"9.31846353326976E-217"},{"lb":"51","ub":"100","p":"6.70171779000614E-162"},{"lb":"101","ub":"150","p":"1.52122150476367E-119"},{"lb":"151","ub":"200","p":"8.22499367788738E-86"},{"lb":"201","ub":"250","p":"6.73812825301519E-59"},{"lb":"251","ub":"300","p":"8.83283900397519E-38"},{"lb":"301","ub":"350","p":"8.07815519348284E-22"},{"lb":"351","ub":"400","p":"1.36423207802494E-10"},{"lb":"401","ub":"450","p":"0.000865267906064952"},{"lb":"451","ub":"500","p":"0.511747241046692"},{"lb":"501","ub":"550","p":"0.486691620113609"},{"lb":"551","ub":"600","p":"0.000695870707126844"},{"lb":"601","ub":"650","p":"9.00841623519E-11"},{"lb":"651","ub":"700","p":"0"},{"lb":"701","ub":"750","p":"0"},{"lb":"751","ub":"800","p":"0"},{"lb":"801","ub":"850","p":"0"},{"lb":"851","ub":"900","p":"0"},{"lb":"901","ub":"950","p":"0"},{"lb":"951","ub":"1000","p":"0"}]}

See Also

BETA_DIST - Calculate pdf or cdf of beta distribution

BINOMDIST - Binomial distribution

BINOMINV - Inverse (quantile) of the binomial distribution

FACTLN - natural logarithm of a factorial