Logo

KURT

Updated 2023-10-23 20:14:56.453000

Syntax

SELECT [westclintech].[wct].[KURT] (
   <@Known_x, float,>

Description

Use the aggregate function KURT to calculate the kurtosis of a dataset. Kurtosis measures the peakedness of a distribution. Kurtosis is computed by taking the fourth moment of a distribution. A high kurtosis has a sharper peak and fatter tails, while a low kurtosis has a more rounded peak and shorter thinner tails. The equation for kurtosis is:

\frac{(n+1)n}{(n-1)(n-2)(n-3)}\frac{\sum_{i=1}^n(x-\bar{x})^4}{k_2^2} -  3\frac{(n-1)^2}{(n-2)(n-3)}

Arguments

@Known_x

the x-values to be used in the KURT calculation. @Known_x is an expression of type float or of a type that can be implicitly converted to float.

Return Type

float

Remarks

If there are fewer than four data points or if the standard deviation of the sample equals zero, KURT returns a NULL

KURT is an AGGREGATE function and follows the same conventions as all other AGGREGATE functions in SQL Server.

Examples

In this example, we calculate the KURT for a single set of x-values

SELECT wct.KURT(x) AS KURT

FROM

(

    SELECT 6.1

    UNION ALL

    SELECT -4.2

    UNION ALL

    SELECT -10

    UNION ALL

    SELECT 9.6

    UNION ALL

    SELECT 9.6

    UNION ALL

    SELECT 4.3

    UNION ALL

    SELECT 2.3

    UNION ALL

    SELECT 7.8

    UNION ALL

    SELECT -7.8

    UNION ALL

    SELECT 7.2

) n(x);

This produces the following result

{"columns":[{"field":"KURT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"KURT":"-0.873841788610509"}]}

In this example, we will populate some temporary table with some information about male height at some selected colleges and then calculate the KURT value. First, create the table and put some data in it:

CREATE TABLE #c

(

    College nvarchar(50),

    Mark bigint,

    Freq bigint

);

INSERT INTO #c

VALUES

('Faber College', 61, 5);

INSERT INTO #c

VALUES

('Faber College', 64, 18);

INSERT INTO #c

VALUES

('Faber College', 67, 42);

INSERT INTO #c

VALUES

('Faber College', 70, 27);

INSERT INTO #c

VALUES

('Faber College', 73, 7);

INSERT INTO #c

VALUES

('Faber College', 76, 1);

INSERT INTO #c

VALUES

('Faber College', 79, 0);

INSERT INTO #c

VALUES

('Harrison University', 61, 4);

INSERT INTO #c

VALUES

('Harrison University', 64, 23);

INSERT INTO #c

VALUES

('Harrison University', 67, 36);

INSERT INTO #c

VALUES

('Harrison University', 70, 27);

INSERT INTO #c

VALUES

('Harrison University', 73, 8);

INSERT INTO #c

VALUES

('Harrison University', 76, 1);

INSERT INTO #c

VALUES

('Harrison University', 79, 1);

INSERT INTO #c

VALUES

('Adams College', 61, 4);

INSERT INTO #c

VALUES

('Adams College', 64, 24);

INSERT INTO #c

VALUES

('Adams College', 67, 42);

INSERT INTO #c

VALUES

('Adams College', 70, 17);

INSERT INTO #c

VALUES

('Adams College', 73, 11);

INSERT INTO #c

VALUES

('Adams College', 76, 2);

INSERT INTO #c

VALUES

('Adams College', 79, 0);

INSERT INTO #c

VALUES

('Western University', 61, 7);

INSERT INTO #c

VALUES

('Western University', 64, 11);

INSERT INTO #c

VALUES

('Western University', 67, 51);

INSERT INTO #c

VALUES

('Western University', 70, 29);

INSERT INTO #c

VALUES

('Western University', 73, 1);

INSERT INTO #c

VALUES

('Western University', 76, 0);

INSERT INTO #c

VALUES

('Western University', 79, 1);

INSERT INTO #c

VALUES

('Jordan College', 61, 11);

INSERT INTO #c

VALUES

('Jordan College', 64, 22);

INSERT INTO #c

VALUES

('Jordan College', 67, 46);

INSERT INTO #c

VALUES

('Jordan College', 70, 18);

INSERT INTO #c

VALUES

('Jordan College', 73, 3);

INSERT INTO #c

VALUES

('Jordan College', 76, 0);

INSERT INTO #c

VALUES

('Jordan College', 79, 0);

Now, calculate the KURT value of the height distribution

SELECT wct.KURT(Freq) as KURT

FROM #c;

This returns the following result

{"columns":[{"field":"KURT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"KURT":"-0.109665119232317"}]}

If we wanted to calculate the KURT by college, we would enter the following statement.

SELECT College,

       wct.KURT(Freq) as KURT

FROM #c

GROUP BY college;

This returns the following result

{"columns":[{"field":"College"},{"field":"KURT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"College":"Adams College","KURT":"0.898726005164902"},{"College":"Faber College","KURT":"0.0858977840344171"},{"College":"Harrison University","KURT":"-1.60545757238505"},{"College":"Jordan College","KURT":"1.69000204265626"},{"College":"Western University","KURT":"1.53200638328263"}]}

If we only wanted to return results not between -1 and 1, then we could enter the following statement.

SELECT College,

       wct.KURT(Freq) as KURT

FROM #c

GROUP BY college

HAVING ABS(wct.KURT(Freq)) > 1;

This returns the following result

{"columns":[{"field":"College"},{"field":"KURT","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"College":"Harrison University","KURT":"-1.60545757238505"},{"College":"Jordan College","KURT":"1.69000204265626"},{"College":"Western University","KURT":"1.53200638328263"}]}