Learn R Programming

steadyICA (version 1.0)

dcovustat: Calculate distance covariance via U-statistics

Description

Calculates the square of the U-statistic formulation of distance covariance. This is faster than the function 'dcov' in the R package 'energy' and requires less memory. Note that negative values are possible in this version.

Usage

dcovustat(x,y,alpha=1)

Arguments

x
A vector or matrix.
y
A vector or matrix with the same number of observations as x, though the number of columns of x and y may differ
alpha
A scaling parameter in the interval (0,2] used for calculating distances.

Value

  • Returns the distance covariance U-statistic.

References

Matteson, D. S. & Tsay, R. Independent component analysis via U-Statistics.

Szekely, G., Rizzo, M. & Bakirov, N. Measuring and testing dependence by correlation of distances. (2007) The Annals of Statistics, 35, 2769-2794.

See Also

multidcov, energy::dcov

Examples

Run this code
x = rnorm(5000)
y = rbinom(5000,1,0.5)
y = y - 1*(y==0)
z = y*exp(-x) #some non-linear dependence

dcovustat(x[1:1000],y[1:1000]) #close to zero

a = Sys.time()
dcovustat(x[1:1000],z[1:1000]) #greater than zero
a = Sys.time() - a

#measures of linear dependence close to zero:
cov(x,z)
cor(rank(x),rank(z))


#dcovustat differs from energy::dcov but are equal in the limit
library(energy)
b = Sys.time()
(dcov(x[1:1000],z[1:1000]))^2
b = Sys.time() - b
as.double(b)/as.double(a) #dcovustat is much faster

## energy::dcov and dcovustat become approximately equal as n increases:
c = Sys.time()
dcovustat(x,z)
c = difftime(Sys.time(), c, sec)
d = Sys.time()
(dcov(x,z)^2)
d = difftime(Sys.time(), d, sec)
as.double(d)/as.double(c)

Run the code above in your browser using DataLab