Logo

SQL Server HYPGEOMDIST Function

Updated 2024-03-08 16:31:30.290000

Description

Use the scalar function HYPGEOMDIST to calculate the probability mass function of the hypergeometric distribution. HYPGEOMDIST calculates the probability of a given number of samples successes, given the sample size, population successes, and the population size. The formula for the probability mass function is:

f(x;N,m,n)=\frac{\binom{m}{k}\binom{N-m}{n-k}}{\binom{N}{n}}

Where

column 1column 2
kis the number of successes in the sample
Nis the size of the sample
mis the number of successes in the population
nis the population size

Syntax

SELECT [westclintech].[wct].[HYPGEOMDIST] ( 
  < @Sample_s , float ,> 
 ,< @Number_sample , float ,> 
 ,< @Population_s , float ,> 
 ,< @Number_population , float ,>)

Arguments

Return Type

float

Remarks

If @Sample_s < 0 or @Sample_s > MIN (@Number_sample , @Population_s ), HYPGEOMDIST returns an error.

If @Sample_s < MAX(0, @Number_sample-@Number_population+@Population_s ), HYPGEOMDIST returns an error.

If @Number_sample = 0 or @Number_sample > @Number_population , HYPGEOMDIST returns an error.

If @Population_s = 0 or @Population_s > @Number_populations , HYPGEOMDIST returns an error.

If @Number_population = 0, HYPGEOMDIST returns an error.

Examples

select wct.HYPGEOMDIST(20, 900, 45, 2000);

This produces the following result.

column 1
0.120021812146482

This value could also have been calculated using the FACTLN function.

select EXP((wct.FACTLN(45) - wct.FACTLN(25) - wct.FACTLN(45 - 25))
           + (wct.FACTLN(1955) - wct.FACTLN(1075) - wct.FACTLN(1955 - 1075))
           - (wct.FACTLN(2000) - wct.FACTLN(1100) - wct.FACTLN(2000 - 1100))
          );

This produces the following result

column 1
0.120021812146482