Logo

KENDALLT_TV

Updated 2023-11-06 16:06:17.407000

Syntax

SELECT * FROM [westclintech].[wct].[KENDALLT_TV](
   <@x_y_Query, nvarchar(max),>)

Description

Use the table-valued function KENDALL_TV to calculate Kendall’s tau (κ), a non-parametric measure of association based on the number of concordances and discordances in paired observations. Concordance occurs when paired observations vary together and discordance occurs when paired observations vary differently. The equation for Kendall’s tau is:

\tau_b = \frac{C-D}{\sqrt{(\binom{n}{2} - T)(\binom{n}{2} - U)}

Where

{
    "columns": [
        {
            "field": "column 1",
            "maxWidth": 100
        },
        {
            "field": "column 2",
            "maxWidth": 325
        }
    ],
    "rows": [
        {
            "column 1": "C",
            "column 2": "is the number of concordant pairs"
        },
        {
            "column 1": "D",
            "column 2": "is the number of discordant pairs"
        },
        {
            "column 1": "n",
            "column 2": "is the number of pairs"
        },
        {
            "column 1": "T",
            "column 2": "is the number of x ties"
        },
        {
            "column 1": "U",
            "column 2": "is the number of y ties"
        }
    ]
}

The function also calculates

\tau_a = \frac{C-D}{\binom{n}{2}}

Arguments

@x_y_Query

a T-SQL statement, as a string, that specifies the subject, rater and rating values.

Return Type

table

{"columns": [{"field": "colName", "headerName": "Name", "header": "name"}, {"field": "colDatatype", "headerName": "Type", "header": "type"}, {"field": "colDesc", "headerName": "Description", "header": "description", "minWidth": 1000}], "rows": [{"id": "6d9c5fcd-7b9b-4787-8b62-3fc58291092e", "colName": "Tau_b", "colDatatype": "float", "colDesc": "the Kendall tau b statistic"}, {"id": "b0c1aba1-8dd4-4fbd-bab2-964988337d5f", "colName": "Zb", "colDatatype": "float", "colDesc": "the z-value for tau b"}, {"id": "7886bafc-1a1d-4dd3-b35b-d1038d7a6c87", "colName": "Pb", "colDatatype": "float", "colDesc": "the p-value for tau b"}, {"id": "52a34e03-3810-4a40-8bbf-8b13417f4eeb", "colName": "SDb", "colDatatype": "float", "colDesc": "the standard deviation for tau b"}, {"id": "e7aa1a89-a002-4c63-abcd-19971fa8a6a7", "colName": "Tau_a", "colDatatype": "float", "colDesc": "the Kendall tau a statistic"}, {"id": "20570865-fd9c-4d13-a863-0c62ec03477d", "colName": "Za", "colDatatype": "float", "colDesc": "the z-value for tau a"}, {"id": "84f27368-0cc9-486f-9a50-d161a253c32b", "colName": "Pa", "colDatatype": "float", "colDesc": "the p-value for tau a"}, {"id": "8a966ddb-cf7b-488f-b59b-0b9ba7072d8c", "colName": "SDa", "colDatatype": "float", "colDesc": "the standard deviation for tau a"}, {"id": "6e7dab51-05a3-47f3-abe4-e20494239b63", "colName": "C", "colDatatype": "float", "colDesc": "the number of concordant pairs"}, {"id": "70c4edfc-d3b0-4800-8a8c-9c2799a293f2", "colName": "D", "colDatatype": "float", "colDesc": "the number of discordant pairs"}, {"id": "27ca0f73-9fbb-43a3-ba85-a631b856401b", "colName": "S", "colDatatype": "float", "colDesc": "C - D"}, {"id": "85c0e3a0-901c-480b-a085-346d6dc9eb57", "colName": "T", "colDatatype": "float", "colDesc": "the number of x ties"}, {"id": "07d21c31-6c73-47d8-b347-a9ed1f98911b", "colName": "U", "colDatatype": "float", "colDesc": "the number of y ties"}, {"id": "32326c09-9605-43f2-8d79-22cd9139d09d", "colName": "N", "colDatatype": "float", "colDesc": "the number of pairs"}]}

Remarks

The function is insensitive to order.

If x is NULL or y is NULL the pair is not included in the calculations.

Examples

SELECT *

INTO #k

FROM

(

    SELECT 2.5,

           1

    UNION ALL

    SELECT 2.5,

           1

    UNION ALL

    SELECT 2.5,

           1

    UNION ALL

    SELECT 2.5,

           1

    UNION ALL

    SELECT 5,

           2

    UNION ALL

    SELECT 6.5,

           1

    UNION ALL

    SELECT 6.5,

           1

    UNION ALL

    SELECT 10,

           2

    UNION ALL

    SELECT 10,

           1

    UNION ALL

    SELECT 10,

           1

    UNION ALL

    SELECT 10,

           1

    UNION ALL

    SELECT 10,

           1

    UNION ALL

    SELECT 14,

           1

    UNION ALL

    SELECT 14,

           1

    UNION ALL

    SELECT 14,

           2

    UNION ALL

    SELECT 16,

           2

    UNION ALL

    SELECT 17,

           2

) n(x, y);

SELECT p.*

FROM wct.KENDALLT_TV('SELECT x,y FROM #k') k

    --This CROSS APPLY UNPIVOTS the tvf columns for formatting

    CROSS APPLY

(

    SELECT 'tau_a',

           tau_a

    UNION ALL

    SELECT 'tau_b',

           tau_b

    UNION ALL

    SELECT 'C',

           C

    UNION ALL

    SELECT 'D',

           D

    UNION ALL

    SELECT 'S',

           S

    UNION ALL

    SELECT 'T',

           T

    UNION ALL

    SELECT 'U',

           U

    UNION ALL

    SELECT 'za',

           za

    UNION ALL

    SELECT 'zb',

           zb

    UNION ALL

    SELECT 'SDa',

           SDa

    UNION ALL

    SELECT 'SDb',

           SDb

    UNION ALL

    SELECT 'pa',

           pa

    UNION ALL

    SELECT 'pb',

           pb

    UNION ALL

    SELECT 'N',

           N

) p(stat, value_stat);

DROP TABLE #k;

This produces the following result.

{"columns":[{"field":"stat"},{"field":"k","headerClass":"ag-right-aligned-header","cellClass":"ag-right-aligned-cell"}],"rows":[{"stat":"tau_a","k":"0.25"},{"stat":"tau_b","k":"0.407543806262577"},{"stat":"C","k":"44"},{"stat":"D","k":"10"},{"stat":"S","k":"34"},{"stat":"T","k":"20"},{"stat":"U","k":"76"},{"stat":"za","k":"1.40054934277178"},{"stat":"zb","k":"1.77779733948549"},{"stat":"SDa","k":"24.2761886080442"},{"stat":"SDb","k":"18.5622957505103"},{"stat":"pa","k":"0.0806744391578792"},{"stat":"pb","k":"0.0754371456202263"},{"stat":"N","k":"17"}]}