SQL Server NEGBINOMDIST Function
Updated 2024-03-12 20:51:51.710000
Description
Use the scalar function NEGBINOMDIST to calculate the negative binomial distribution. NEGBINOMDIST returns the probability that there will be k failures before the rth success, when the constant probability of a success is p. The formula for the probability mass function of the negative binomial distribution is:
f(k; r, p) \equiv \Pr(X = k) = \binom{k+r-1}{k} (1-p)^k p^r
Where
| column 1 | column 2 |
|---|---|
| k | is the number of failures |
| r | is the number of successes |
| p | is the probability of a success |
Syntax
SELECT [westclintech].[wct].[NEGBINOMDIST] (
<@Number_f, float,>
,<@Number_s, float,>
,<@Probability_s, float,>)
Arguments
@Number_f
is the number of failures. @Number_f is an expression of type float or of a type that can be implicitly converted to float.
@Number_s
is the number of successes. @Number_s is an expression of type float or of a type that can be implicitly converted to float.
@Probability_s
is the probability of a success. @Probability_s is an expression of type float or of a type that can be implicitly converted to float.
Return Type
float
Remarks
If @Probability_s <0 or @Probability_s > 1, NEGBINOMDIST returns an error.
If @Number_f < 0 or @Number_s < 1, NEGBINOMDIST returns an error.
NEGBINOMDIST = BINOMDIST(@Number_s, @Number_f + @Number_s, @Probability, 'False') * @Number_s / (@Number_f + @Number_s)
Examples
SELECT wct.NEGBINOMDIST(4, 90, 0.975);
This produces the following result.
| column 1 |
|---|
| 0.116820452331376 |
SELECT wct.BINOMDIST(90, 90 + 4, 0.975, 'False') * 90 / (90 + 4);
This produces the following result.
| column 1 |
|---|
| 0.116820452331368 |
select wct.BETADIST(0.975, 90, 4 + 1, NULL, NULL) - wct.BETADIST(0.975, 90, 4,
NULL, NULL);
This produces the following result.
| column 1 |
|---|
| 0.116820452331374 |