SQL Server Kolmogorov-Smirnov complementary cumulative distribution function

KSccdf

Updated: 29 June 2012

Use KSccdf to compute the complementary cumulative probability P[Dn >= x] of the Kolmogorov-Smirnov distribution with sample size n at x.
Syntax
SELECT [wctStatistics].[wct].[KSccdf](
<@n, int,>
,<@k, float,>)
Arguments
@n
is the sample size. @n is an expression of type int or of a type that can be implicitly converted to int
@x
is the maximum magnitude of the discrepancy between the empirical and proposed distributions. @x is an expression of type float or of a type that can be implicitly converted to float
Return Types
Float
Remarks
·         If @n < 0 then KSccdf = 1
·         If @x < 0 then KSccdf = 1
Examples
SELECT n
,sqrt(18.0/n) as x
,wct.KSCCDF(n, sqrt(18.0/n)) as ks
FROM (VALUES (50.0),(100.0),(500.0),(1000.0),(5000.0),(10000.0),(50000.0),(10E5),(10E6),(10E7),(10E8))p(n)
This produces the following result.
n                      x                     ks
---------------------- ---------------------- ----------------------
50                    0.6    9.6340704561422E-18
100      0.424264068711929   7.60653219848608E-17
500      0.189736659610103   3.09340954271647E-16
1000      0.134164078649987   3.69599264243387E-16
5000                   0.06   4.33712332368773E-16
10000     0.0424264068711929   4.44862619998983E-16
50000     0.0189736659610103   4.56828378005821E-16
1000000    0.00424264068711928   4.62531376662394E-16
10000000    0.00134164078649987   4.63483518913332E-16
100000000   0.000424264068711929   4.63772741835367E-16

1000000000   0.000134164078649987   4.63863011932784E-16