RunningKURT_P
Updated: 30 June 2013
Use RunningKURT_P to calculate the population kurtosis of column values in an ordered resultant table, without the need for a self-join. The population kurtosis is calculated over all the values from the first value to the last value in the ordered group or partition. If the column values are presented to the functions out of order, an error message will be generated.
Syntax
SELECT [westclintech].[wct].[RunningKURT_P](
<@X, float,>
,<@RowNum, int,>
,<@Id, tinyint,>)
Arguments
@X
the value passed into the function. @X is an expression of type float or of a type that can be implicitly converted to float.
@RowNum
the number of the row within the group for which the population kurtosis is being calculated. If @RowNum for the current row in a set is less than or equal to the previous @RowNum and @RowNum is not equal to 1, an error message will be generated. @RowNum is an expression of type int or of a type that can be implicitly converted to int.
@Id
a unique identifier for the RunningKURT_P calculation. @Id allows you to specify multiple running sample skewness calculations within a resultant table. @Id is an expression of type tinyint or of a type that can be implicitly converted to tinyint.
Remarks
· If @Id is NULL then @Id = 0.
· To calculate moving population kurtosis, use the MovingKURT_P function.
· To calculate the population kurtosis for an entire data set, use the KURTOSIS_P function.
· If @RowNum is equal to 1, RunningKURT_P is equal to zero.
· @RowNum must be in ascending order.
· There may be cases where the order in which the data are returned to the function and the order in which the results are returned are different, generally due to parallelism. You can use OPTION(MAXDOP 1) or OPTION(MAXDOP 1,FORCE ORDER) to help eliminate this problem
Example
In this example, we have 20 rows of data and we want to caculate the population kurtosis of x and y starting from the first row. Note that the @Id value for each RunningKURT_P column is different.
SELECT rn
,x
,y
,wct.RunningKURT_P(x,rn,NULL) as [KURT_P x]
,wct.RunningKURT_P(y,rn,1) as [KURT_P y]
FROM (
SELECT 1,101,117 UNION ALL
SELECT 2,91,97 UNION ALL
SELECT 3,96,121 UNION ALL
SELECT 4,96,103 UNION ALL
SELECT 5,86,74 UNION ALL
SELECT 6,95,80 UNION ALL
SELECT 7,91,105 UNION ALL
SELECT 8,102,72 UNION ALL
SELECT 9,94,108 UNION ALL
SELECT 10,110,94 UNION ALL
SELECT 11,121,85 UNION ALL
SELECT 12,115,90 UNION ALL
SELECT 13,112,96 UNION ALL
SELECT 14,100,97 UNION ALL
SELECT 15,124,106 UNION ALL
SELECT 16,92,61 UNION ALL
SELECT 17,92,107 UNION ALL
SELECT 18,139,92 UNION ALL
SELECT 19,95,101 UNION ALL
SELECT 20,90,104
)n(rn,x,y)
This produces the following result.
rn x y KURT_P x KURT_P y
---- ----------- ----------- ---------------------- ----------------------
1 101 117 NULL NULL
2 91 97 NULL NULL
3 96 121 NULL NULL
4 96 103 -1 -1.74865292550528
5 86 74 -1.04437869822485 -0.902696778864364
6 95 80 -0.633226500060854 -1.44218560769896
7 91 105 -0.650501377317926 -1.19882743064317
8 102 72 -0.879228145551851 -1.44526829938784
9 94 108 -0.635100000000002 -1.33892142165806
10 110 94 -0.0343734328383594 -1.19062985993896
11 121 85 0.585845984277592 -1.20772827889674
12 115 90 -0.465031072662944 -1.08938476633362
13 112 96 -0.873940871576376 -0.930916295217799
14 100 97 -0.699460324915596 -0.775639728744614
15 124 106 -0.852568200208419 -0.750774228883491
16 92 61 -0.755125315989483 -0.579900317705061
17 92 107 -0.639278721237954 -0.519940090433461
18 139 92 0.319124122338282 -0.40135506515209
19 95 101 0.523775201101926 -0.263907628445724
20 90 104 0.654415843064204 -0.150813838602128