Compute Kendall rank correlation coefficient between two objects. Kendall is a coefficient used in statistics to measure the ordinal association between two measured quantities. A tau test is a non-parametric hypothesis test for statistical dependence based on the tau coefficient. The 'kendallTau' function applies the "kendall" method from 'stats::cor' with some previous treatment in the data, such as converting floating numbers into ranks (from the higher being the first and negative being the last) and the possibility to remove zeros from incomplete ranks.

Perform a pairwise permutation test to assess statistical differences in Kendall's Tau correlation between two or more groups.

kendallTau(x, y, null.rm = TRUE, average = TRUE, na.omit = FALSE, ...)

# Default S3 method
kendallTau(
  x,
  y,
  null.rm = TRUE,
  ...,
  alternative = c("two.sided", "greater", "less")
)

# S3 method for class 'matrix'
kendallTau(
  x,
  y,
  null.rm = TRUE,
  average = TRUE,
  na.omit = FALSE,
  ...,
  alternative = c("two.sided", "greater", "less")
)

# S3 method for class 'rankings'
kendallTau(x, y, ...)

# S3 method for class 'grouped_rankings'
kendallTau(x, y, ...)

# S3 method for class 'paircomp'
kendallTau(x, y, ...)

kendallTau_bootstrap(x, y, nboot = 100, seed = NULL, ...)

kendallTau_permute(x, y, split, n.permutations = 500)

Arguments

x

a numeric vector, matrix or data frame

y

a vector, matrix or data frame with compatible dimensions to x

null.rm

logical, to remove zeros from x and y

average

logical, if FALSE returns the kendall and N-effective for each entry

na.omit

logical, if TRUE ignores entries with kendall = NA when computing the average

...

further arguments affecting the Kendall tau produced. See details

alternative

the alternative hypothesis, one of "two.sided" (the default), "greater" (positive association) or "less" (negative association). The p-value is returned in the column Pr(>|z|) whatever the alternative

nboot

integer, the size of the bootstrap sample

seed

integer, the seed for random number generation. If NULL (the default), the current random number stream is used

split

a vector indicating the splitting rule for the test

n.permutations

an integer, the number of permutations to perform

Value

The Kendall correlation coefficient, the Effective N (the equivalent N if all items were compared to all items), the z value and its p-value. For matrices, each row is treated as an independent ranking: the average tau weights rows by their number of pairs, and the z value uses the null variance of that weighted average. The null variance assumes no ties; use kendallTau_permute for an exact test with small or tied data.

A data.frame containing:

observed_diff

observed absolute differences in Kendall's tau for all group pairs.

p_values

p-values from the permutation test for all group pairs.

Details

kendallTau_bootstrap() resamples the rows (participants) with replacement nboot times and returns the pair-weighted average tau of each resample. The spread of these values estimates the sampling variability of the average tau, for example to draw boxplots by trait. Rows with fewer than two ranked items, or with tau = NA, are dropped first. When seed is given, the resamples are reproducible and the caller's random number stream is left unchanged.

References

Kendall M. G. (1938). Biometrika, 30(1–2), 81–93. doi:10.1093/biomet/30.1-2.81

See also

cor

kendallTau

Other goodness-of-fit functions: kendallW(), pseudoR2()

Author

Kauê de Sousa and Jacob van Etten

Kauê de Sousa

Examples


# Vector based example same as stats::cor(x, y, method = "kendall")
# but showing N-effective
x = c(1, 2, 3, 4, 5)

y = c(1, 1, 3, 2, NA)

w = c(1, 1, 3, 2, 5)

kendallTau(x, y)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     0.5477      4.0000 1.1163   0.2643

kendallTau(x, w)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     0.7379      5.0000 1.8074   0.0707

# Matrix and PlacketLuce ranking example 

library("PlackettLuce")
 
R = matrix(c(1, 2, 4, 3,
             1, 4, 2, 3,
             1, 2, NA, 3,
             1, 2, 4, 3,
             1, 3, 4, 2,
             1, 4, 3, 2), nrow = 6, byrow = TRUE)
colnames(R) = LETTERS[1:4]

G = group(as.rankings(R), 1:6)

mod = pltree(G ~ 1, data = G)

preds = predict(mod)

kendallTau(R, preds)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     0.6364      8.6394 3.0632   0.0022

# Also returns raw values (no average) 

kendallTau(R, preds, average = FALSE)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     0.6667      4.0000 1.3587   0.1742
#> 2:     0.3333      4.0000 0.6794   0.4969
#> 3:     0.3333      3.0000 0.5222   0.6015
#> 4:     0.6667      4.0000 1.3587   0.1742
#> 5:     1.0000      4.0000 2.0381   0.0415
#> 6:     0.6667      4.0000 1.3587   0.1742

# Choose to ignore entries with NA
R2 = matrix(c(1, 2, 4, 3,
              1, 4, 2, 3,
              NA, NA, NA, NA,
              1, 2, 4, 3,
              1, 3, 4, 2,
              1, 4, 3, 2), nrow = 6, byrow = TRUE)

kendallTau(R, R2, average = FALSE)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     1.0000      4.0000 2.0381   0.0415
#> 2:     1.0000      4.0000 2.0381   0.0415
#> 3:         NA      1.0000     NA       NA
#> 4:     1.0000      4.0000 2.0381   0.0415
#> 5:     1.0000      4.0000 2.0381   0.0415
#> 6:     1.0000      4.0000 2.0381   0.0415

kendallTau(R, R2, average = TRUE)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     1.0000      8.2621 4.5573   0.0000

kendallTau(R, R2, average = TRUE, na.omit = TRUE)
#>    kendallTau N_effective Zvalue Pr(>|z|)
#>         <dbl>       <dbl>  <dbl>    <dbl>
#> 1:     1.0000      8.2621 4.5573   0.0000

# Variability of the average tau across participants
boot = kendallTau_bootstrap(R, preds, nboot = 200, seed = 1)
quantile(boot, c(0.025, 0.5, 0.975))
#>      2.5%       50%     97.5% 
#> 0.4072222 0.6363636 0.8333333 

if (FALSE) { # interactive()
set.seed(42)
x = rnorm(100)
y = rnorm(100)
split = rep(c("Group1", "Group2", "Group3"), length.out = 100)
kendallTau_permute(x, y, split)

data("breadwheat", package = "gosset")

x = rank_tricot(breadwheat, 
                items = paste0("variety_", letters[1:3]),
                input = c("yield_best", "yield_worst"),
                validate.rankings = TRUE)

y = rank_tricot(breadwheat, 
                items = paste0("variety_", letters[1:3]),
                input = c("overall_best", "overall_worst"),
                validate.rankings = TRUE)
                
kendallTau_permute(x, y, 
                split = rep(c("Group1", "Group2", "Group3"), length.out = nrow(breadwheat)), 
                n.permutations = 100)
                
}