MULTINOM
Updated 2024-03-08 21:49:58.933000
Syntax
SELECT [westclintech].[wct].[MULTINOM] (
<@x, int,>
,<@p, float,>)
Description
Use the aggregate function MULTINOM to calculate the probability distribution of the outcomes of a multinomial experiment. Use MULTINOM for statistical experiments where:
• The experiment consists of x repeated trials.• Each trial has a discrete number of possible outcomes.• On any given trial, the probability that a particular outcome will occur is constant• The trials are independent; that is, the outcome on one trial does not affect the outcome on other trials.
P=\frac{x!}{x_1!x_2!\ldots x_k!}p_1^{x_1}p_2^{x_2}\ldots p_k^{x_k}
Arguments
@p
The probability for that bin.
@x
The bin value for the trials.
Return Type
float
Remarks
If @p is NULL then @p = 1
If @x is NULL then it is not included in the calculation.
@p is internally normalized so that SUM(p) = 1
x! is the factorial of the sum of @x
Examples
Example #1
Suppose we have an urn containing 9 marbles. Two are red, three are green, and four are blue. 5 marbles are randomly selected from the urn with replacement. What is the probability of selecting 2 green marbles and 3 blue marbles?
SELECT wct.MULTINOM(x, p) as MULTINOM
FROM
(
VALUES
('red', 0, 2),
('green', 2, 3),
('blue', 3, 4)
) n (c, x, p);
This produces the following result.
{"columns":[{"field":"MULTINOM","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"MULTINOM":"0.0975461057765585"}]}
Example #2
Suppose we roll a dice 5 times and obtain three ones and two sixes; in other words, a 6-tuple of (3,0,0,0,0,2). We can calculate the probability with the following SQL.
SELECT wct.MULTINOM(x, p) as MULTINOM
FROM
(
VALUES
(3, NULL),
(0, NULL),
(0, NULL),
(0, NULL),
(0, NULL),
(2, NULL)
) n (x, p);
This produces the following result.
{"columns":[{"field":"MULTINOM","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"MULTINOM":"0.00128600823045268"}]}
See Also
LCHOOSE - Natural logarithm of the binomial coefficient
LPERMUT - Calculate the natural logarithm of the PERMUT function.
LPERMUTA - calculate the natural logarithm of the PERMUTATIONA function.