KENDALLT_TV
Updated: 24 May 2013
Use the table-valued function KENDALLT_TV to calculate Kendall’s tau (t), 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:
Where
C is the number of concordant pairs
D is the number of discordant pairs
n is the number of pairs
T is the number of x ties
U is the number of y ties
The function also calculates
Syntax
SELECT * FROM [wctStatistics].[wct].[KENDALLT_TV](
<@x_y_Query, nvarchar(max),>)
Arguments
@InputData_RangeQuery
a T-SQL statement, as a string, that specifies the subject, rater, and rating values.
Return Type
RETURNS TABLE (
[Tau_b] [float] NULL,
[Zb] [float] NULL,
[Pb] [float] NULL,
[SDb] [float] NULL,
[Tau_a] [float] NULL,
[Za] [float] NULL,
[Pa] [float] NULL,
[SDa] [float] NULL,
[C] [float] NULL,
[D] [float] NULL,
[S] [float] NULL,
[T] [float] NULL,
[U] [float] NULL,
[N] [float] NULL
)
Column
|
Column Description
|
Tau_b
|
the Kendall tau b statistic
|
Zb
|
the z-value for tau b
|
Pb
|
the p-value for tau b
|
SDb
|
the standard deviation for tau b
|
Tau_a
|
the Kendall tau a statistic
|
Za
|
the z-value for tau a
|
Pa
|
the p-value for tau a
|
SDa
|
the standard deviation for tau a
|
C
|
the number of concordant pairs
|
D
|
the number of discordant pairs
|
S
|
C – D
|
T
|
the number of x ties
|
U
|
the number of y ties
|
N
|
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.