Logo

RunningKURT_S

Updated 2023-11-14 15:06:24.627000

Syntax

SELECT [westclintech].[wct].[RunningKURT_S](
  <@X, float,>
 ,<@RowNum, int,>
 ,<@Id, tinyint,>)

Description

Use the scalar function RunningKURT_S to calculate the sample kurtosis of column values in an ordered resultant table, without the need for a self-join. The sample 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_S 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 sample 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 sample kurtosis, use the MovingKURT_S function.

To calculate the sample kurtosis for an entire data set, use the KURTOSIS_S function.

If @RowNum is equal to 1, RunningKURT_S 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 sample kurtosis of x and y starting from the first row. No te that the @Id value for each RunningKURT_S column is different.

SELECT rn,

       x,

       y,

       wct.RunningKURT_S(x, rn, NULL) as [KURT_S x],

       wct.RunningKURT_S(y, rn, 1) as [KURT_S 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_S x"},{"field":"KURT_S y"}],"rows":[{"rn":"1","x":"101","y":"117","KURT_S x":"NULL","KURT_S y":"NULL"},{"rn":"2","x":"91","y":"97","KURT_S x":"NULL","KURT_S y":"NULL"},{"rn":"3","x":"96","y":"121","KURT_S x":"NULL","KURT_S y":"NULL"},{"rn":"4","x":"96","y":"103","KURT_S x":"1.5","KURT_S y":"-4.11489694128959"},{"rn":"5","x":"86","y":"74","KURT_S x":"-0.177514792899409","KURT_S y":"0.389212884542543"},{"rn":"6","x":"95","y":"80","KURT_S x":"0.653089374822509","KURT_S y":"-1.70637468912197"},{"rn":"7","x":"91","y":"105","KURT_S x":"0.238796694436977","KURT_S y":"-1.07718583354361"},{"rn":"8","x":"102","y":"72","KURT_S x":"-0.446379105658887","KURT_S y":"-1.63506342871445"},{"rn":"9","x":"94","y":"108","KURT_S x":"-0.0668571428571463","KURT_S y":"-1.40746937458679"},{"rn":"10","x":"110","y":"94","KURT_S x":"0.9035183955179","KURT_S y":"-1.14057778810637"},{"rn":"11","x":"121","y":"85","KURT_S x":"1.80974330712932","KURT_S y":"-1.17954713149457"},{"rn":"12","x":"115","y":"90","KURT_S x":"-0.00554937100889941","KURT_S y":"-0.997578017618969"},{"rn":"13","x":"112","y":"96","KURT_S x":"-0.6802006038621","KURT_S y":"-0.767217614514457"},{"rn":"14","x":"100","y":"97","KURT_S x":"-0.44238457089804","KURT_S y":"-0.554922326554543"},{"rn":"15","x":"124","y":"106","KURT_S x":"-0.685738954145421","KURT_S y":"-0.53957325173014"},{"rn":"16","x":"92","y":"61","KURT_S x":"-0.56349975591933","KURT_S y":"-0.31799220337797"},{"rn":"17","x":"92","y":"107","KURT_S x":"-0.419582246269193","KURT_S y":"-0.255917838308746"},{"rn":"18","x":"139","y":"92","KURT_S x":"0.854487881313605","KURT_S y":"-0.115157025183854"},{"rn":"19","x":"95","y":"101","KURT_S x":"1.09029070734079","KURT_S y":"0.0477693152924239"},{"rn":"20","x":"90","y":"104","KURT_S x":"1.22585595223078","KURT_S y":"0.175899602607029"}]}