NEGBINOMDIST
Updated 2024-03-12 20:51:51.710000
Syntax
SELECT [westclintech].[wct].[NEGBINOMDIST] (
<@Number_f, float,>
,<@Number_s, float,>
,<@Probability_s, float,>)
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
{
"columns": [
{
"field": "column 1",
"maxWidth": 100
},
{
"field": "column 2",
"maxWidth": 325
}
],
"rows": [
{
"column 1": "k",
"column 2": "is the number of failures"
},
{
"column 1": "r",
"column 2": "is the number of successes"
},
{
"column 1": "p",
"column 2": "is the probability of a success"
}
]
}
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.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"0.116820452331376"}]}
SELECT wct.BINOMDIST(90, 90 + 4, 0.975, 'False') * 90 / (90 + 4);
This produces the following result.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"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.
{"columns":[{"field":"column 1","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"column 1":"0.116820452331374"}]}