RunningKURT_P
Updated 2023-11-14 15:04:58.960000
Syntax
SELECT [westclintech].[wct].[RunningKURT_P](
<@X, float,>
,<@RowNum, int,>
,<@Id, tinyint,>)
Description
Use the scalar function 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.
Arguments
@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.
@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.
Return Type
float
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
Examples
In this example, we have 20 rows of data and we want to calculate 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.
{"columns":[{"field":"rn","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"x","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"y","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"},{"field":"KURT_P x"},{"field":"KURT_P y"}],"rows":[{"rn":"1","x":"101","y":"117","KURT_P x":"NULL","KURT_P y":"NULL"},{"rn":"2","x":"91","y":"97","KURT_P x":"NULL","KURT_P y":"NULL"},{"rn":"3","x":"96","y":"121","KURT_P x":"NULL","KURT_P y":"NULL"},{"rn":"4","x":"96","y":"103","KURT_P x":"-1","KURT_P y":"-1.74865292550528"},{"rn":"5","x":"86","y":"74","KURT_P x":"-1.04437869822485","KURT_P y":"-0.902696778864364"},{"rn":"6","x":"95","y":"80","KURT_P x":"-0.633226500060854","KURT_P y":"-1.44218560769896"},{"rn":"7","x":"91","y":"105","KURT_P x":"-0.650501377317926","KURT_P y":"-1.19882743064317"},{"rn":"8","x":"102","y":"72","KURT_P x":"-0.879228145551851","KURT_P y":"-1.44526829938784"},{"rn":"9","x":"94","y":"108","KURT_P x":"-0.635100000000002","KURT_P y":"-1.33892142165806"},{"rn":"10","x":"110","y":"94","KURT_P x":"-0.0343734328383594","KURT_P y":"-1.19062985993896"},{"rn":"11","x":"121","y":"85","KURT_P x":"0.585845984277592","KURT_P y":"-1.20772827889674"},{"rn":"12","x":"115","y":"90","KURT_P x":"-0.465031072662944","KURT_P y":"-1.08938476633362"},{"rn":"13","x":"112","y":"96","KURT_P x":"-0.873940871576376","KURT_P y":"-0.930916295217799"},{"rn":"14","x":"100","y":"97","KURT_P x":"-0.699460324915596","KURT_P y":"-0.775639728744614"},{"rn":"15","x":"124","y":"106","KURT_P x":"-0.852568200208419","KURT_P y":"-0.750774228883491"},{"rn":"16","x":"92","y":"61","KURT_P x":"-0.755125315989483","KURT_P y":"-0.579900317705061"},{"rn":"17","x":"92","y":"107","KURT_P x":"-0.639278721237954","KURT_P y":"-0.519940090433461"},{"rn":"18","x":"139","y":"92","KURT_P x":"0.319124122338282","KURT_P y":"-0.40135506515209"},{"rn":"19","x":"95","y":"101","KURT_P x":"0.523775201101926","KURT_P y":"-0.263907628445724"},{"rn":"20","x":"90","y":"104","KURT_P x":"0.654415843064204","KURT_P y":"-0.150813838602128"}]}