KendallTau {mixedCCA} | R Documentation |
Kendall's tau correlation
Description
Calculate Kendall's tau correlation.
\hat{\tau}_{jk} = \frac{2}{n(n-1)}\sum_{1\le i<i'\le n} sign(X_{ji}-X_{ji'}) sign(X_{ki}-X_{ki'})
The function KendallTau
calculates Kendall's tau correlation between two variables, returning a single correlation value. The function Kendall_matrix
returns a correlation matrix.
Usage
KendallTau(x, y)
Kendall_matrix(X, Y = NULL)
Arguments
x |
A numeric vector. |
y |
A numeric vector. |
X |
A numeric matrix (n by p1). |
Y |
A numeric matrix (n by p2). |
Value
KendallTau(x, y)
returns one Kendall's tau correlation value between two vectors, x
and y
.
Kendall_matrix(X)
returns a p1 by p1 matrix of Kendall's tau correlation coefficients. Kendall_matrix(X, Y)
returns a p1 by p2 matrix of Kendall's tau correlation coefficients.
Examples
n <- 100 # sample size
r <- 0.8 # true correlation
### vector input
# Data generation (X1: truncated continuous, X2: continuous)
Z <- mvrnorm(n, mu = c(0, 0), Sigma = matrix(c(1, r, r, 1), nrow = 2))
X1 <- Z[,1]
X1[Z[,1] < 1] <- 0
X2 <- Z[,2]
KendallTau(X1, X2)
Kendall_matrix(X1, X2)
### matrix data input
p1 <- 3; p2 <- 4 # dimension of X1 and X2
JSigma <- matrix(r, nrow = p1+p2, ncol = p1+p2); diag(JSigma) <- 1
Z <- mvrnorm(n, mu = rep(0, p1+p2), Sigma = JSigma)
X1 <- Z[,1:p1]
X1[Z[,1:p1] < 0] <- 0
X2 <- Z[,(p1+1):(p1+p2)]
Kendall_matrix(X1, X2)
[Package mixedCCA version 1.6.2 Index]