Learn R Programming

cdcsis (version 2.0.5)

cdcov.test: Conditional Distance Covariance Independence Test

Description

Performs the nonparametric conditional distance covariance test for conditional independence assumption

Usage

cdcov.test(
  x,
  y,
  z,
  num.bootstrap = 99,
  width,
  distance = FALSE,
  index = 1,
  seed = 1,
  num.threads = 1
)

Value

cdcov.test returns a list with class "htest" containing the following components:

statistic

conditional distance covariance statistic.

p.value

the \(p\)-value for the test.

replicates

the number of local bootstrap procedure replications.

size

sample sizes.

alternative

a character string describing the alternative hypothesis.

method

a character string indicating what type of test was performed.

data.name

description of data.

Arguments

x

a numeric vector, matrix, or dist object

y

a numeric vector, matrix, or dist object

z

z is a numeric vector or matrix. It is the variable being conditioned.

num.bootstrap

the number of local bootstrap procedure replications. Default: num.bootstrap = 99.

width

a user-specified positive value (univariate conditional variable) or vector (multivariate conditional variable) for gaussian kernel bandwidth. Its default value is relies on stats::bw.nrd0 function when conditional variable is univariate, ks::Hpi.diag when conditional variable with at most trivariate, and stats::bw.nrd on the other cases.

distance

if distance = TRUE, x and y will be considered as distance matrices. Default: distance = FALSE.

index

exponent on Euclidean distance, in \((0,2]\)

seed

the random seed

num.threads

number of threads. Default num.threads = 1.

References

Wang, X., Pan, W., Hu, W., Tian, Y. and Zhang, H., 2015. Conditional distance correlation. Journal of the American Statistical Association, 110(512), pp.1726-1734.

See Also

cdcov

Examples

Run this code
# \donttest{

library(cdcsis)
set.seed(1)
num <- 50
################# Conditional Independent #################
## Case 1:
cov_mat <- matrix(c(1, 0.36, 0.6, 0.36, 1, 0.6, 0.6, 0.6, 1), nrow = 3)
dat <- mvtnorm::rmvnorm(n = num, sigma = cov_mat)
x <- dat[, 1]
y <- dat[, 2]
z <- dat[, 3]
cdcov.test(x, y, z)
## Case 2:
z <- rnorm(num)
x <- 0.5 * (z^3 / 7 + z / 2) + tanh(rnorm(num))
x <- x + x^3 / 3
y <- (z^3 + z) / 3 + rnorm(num)
y <- y + tanh(y / 3)
cdcov.test(x, y, z, num.bootstrap = 99)

################# Conditional Dependent #################
## Case 3:
cov_mat <- matrix(c(1, 0.7, 0.6, 0.7, 1, 0.6, 0.6, 0.6, 1), nrow = 3)
dat <- mvtnorm::rmvnorm(n = num, sigma = cov_mat)
x <- dat[, 1]
y <- dat[, 2]
z <- dat[, 3]
cdcov.test(x, y, z, width = 0.5)
## Case 4:
z <- matrix(rt(num * 4, df = 2), nrow = num)
x <- z
y <- cbind(sin(z[, 1]) + cos(z[, 2]) + (z[, 3])^2 + (z[, 4])^2, 
           (z[, 1])^2 + (z[, 2])^2 + z[, 3] + z[, 4])
z <- z[, 1:2]
cdcov.test(x, y, z, seed = 2)

################# Distance Matrix Input #################
x <- dist(x)
y <- dist(y)
cdcov.test(x, y, z, seed = 2, distance = TRUE)
# }

Run the code above in your browser using DataLab