Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

corKendall

(Fast) Computation of Pairwise Kendall's Taus


Description

For a data matrix x, compute the Kendall's tau “correlation” matrix, i.e., all pairwise Kendall's taus between the columns of x.

By default and when x has no missing values (NAs), the fast O(n log(n)) algorithm of cor.fk() is used.

Usage

corKendall(x, checkNA = TRUE,
           use = if(checkNA && anyNA(x)) "pairwise" else "everything")

Arguments

x

data, a n x p matrix (or less efficiently a data.frame), or a numeric vector which is treated as n x 1 matrix.

checkNA

logical indicating if x should be checked for NAs and in the case of NA's and when use is not specified (missing), cor(*, use = "pairwise") should be used. Note that corKendall(x, checkNA = FALSE) will produce an error when x has NA's.

use

a string to determine the treatment of NAs in x, see cor; its default determined via checkNA. When this differs from "everything", R's cor is used; otherwise pcaPP's cor.fk() which cannot deal with NAs.

Value

The p x p matrix K of pairwise Kendall's taus, with K[i,j] := tau(x[,i], x[,j]).

See Also

cor.fk() from pcaPP (used by default when there are no missing values (NAs) in x).

etau() or fitCopula(*, method = "itau") make use of corKendall().

Examples

## If there are no NA's, corKendall() is faster than cor(*, "kendall")
## and gives the same :

system.time(C1 <- cor(swiss, method="kendall"))
system.time(C2 <- corKendall(swiss))
stopifnot(all.equal(C1, C2,  tol = 1e-5))

## In the case of missing values (NA), corKendall() reverts to
## cor(*, "kendall", use = "pairwise") {no longer very fast} :

swM <- swiss # shorter names and three missings:
colnames(swM) <- abbreviate(colnames(swiss), min=6)
swM[1,2] <- swM[7,3] <- swM[25,5] <- NA
(C3 <- corKendall(swM)) # now automatically uses the same as
stopifnot(identical(C3, cor(swM, method="kendall", use="pairwise")))
## and is quite close to the non-missing "truth":
stopifnot(all.equal(unname(C3), unname(C2), tol = 0.06)) # rel.diff.= 0.055

try(corKendall(swM, checkNA=FALSE)) # --> Error
## the error is really from  pcaPP::cor.fk(swM)

copula

Multivariate Dependence with Copulas

v1.0-1
GPL (>= 3) | file LICENCE
Authors
Marius Hofert [aut] (<https://orcid.org/0000-0001-8009-4665>), Ivan Kojadinovic [aut] (<https://orcid.org/0000-0002-2903-1543>), Martin Maechler [aut, cre] (<https://orcid.org/0000-0002-8685-9910>), Jun Yan [aut] (<https://orcid.org/0000-0003-4401-7296>), Johanna G. Nešlehová [ctb] (evTestK(), <https://orcid.org/0000-0001-9634-4796>), Rebecca Morger [ctb] (fitCopula.ml(): code for free mixCopula weight parameters)
Initial release
2020-12-07

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.