Logo

KENDALLT

Updated 2023-11-06 15:28:16.273000

Syntax

SELECT [westclintech].[wct].[KENDALLT](
  <@x_y_Query, nvarchar(max),>
 ,<@RV, nvarchar(4000),>)

Description

Use the scalar function KENDALLT 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

@RV

the value to be returned by the function. Use the following values:

{
    "columns": [
        {
            "field": "RV",
            "maxWidth": 200
        },
        {
            "field": "description",
            "maxWidth": 325
        }
    ],
    "rows": [
        {
            "RV": "'TAU','TAU_B','TAUB'",
            "description": "tau 𝑏"
        },
        {
            "RV": "'TAU_A','TAUA'",
            "description": "tau 𝑎"
        },
        {
            "RV": "'Z','Z_B','ZB'",
            "description": "the z-statistic for tau 𝑏"
        },
        {
            "RV": "'Z_A','ZA'",
            "description": "the z-statistic for tau 𝑎"
        },
        {
            "RV": "'P','P_B','PB'",
            "description": "the p-value for tau 𝑏"
        },
        {
            "RV": "'P_A','PA'",
            "description": "the p-value for tau 𝑎"
        },
        {
            "RV": "'SD','SD_B','SDB'",
            "description": "the standard deviation for tau 𝑏"
        },
        {
            "RV": "'SD_A','SDB'",
            "description": "the standard deviation for tau 𝑎"
        },
        {
            "RV": "'C'",
            "description": "the number of concordant pairs"
        },
        {
            "RV": "'D'",
            "description": "the number of discordant pairs"
        },
        {
            "RV": "'S'",
            "description": "C – D"
        },
        {
            "RV": "'T'",
            "description": "the number of x ties"
        },
        {
            "RV": "'U'",
            "description": "the number of y ties"
        },
        {
            "RV": "'N'",
            "description": "the number of pairs"
        }
    ]
}

@x_y_Query

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

Return Type

float

Remarks

The function is insensitive to order.

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

To return multiple values, use the table-valued function KENDALLT_TV.

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.stat,

       wct.KENDALLT('SELECT x,y FROM #k', p.stat) k

FROM

(

    SELECT 'tau_a'

    UNION ALL

    SELECT 'tau_b'

    UNION ALL

    SELECT 'C'

    UNION ALL

    SELECT 'D'

    UNION ALL

    SELECT 'S'

    UNION ALL

    SELECT 'T'

    UNION ALL

    SELECT 'U'

    UNION ALL

    SELECT 'za'

    UNION ALL

    SELECT 'zb'

    UNION ALL

    SELECT 'SDa'

    UNION ALL

    SELECT 'SDb'

    UNION ALL

    SELECT 'pa'

    UNION ALL

    SELECT 'pb'

    UNION ALL

    SELECT 'N'

) p(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"}]}