cdcov.test {cdcsis} | R Documentation |
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
)
Arguments
x |
a numeric vector, matrix, or |
y |
a numeric vector, matrix, or |
z |
|
num.bootstrap |
the number of local bootstrap procedure replications. Default: |
width |
a user-specified positive value (univariate conditional variable) or vector (multivariate conditional variable) for
gaussian kernel bandwidth. Its default value is relies on |
distance |
if |
index |
exponent on Euclidean distance, in |
seed |
the random seed |
num.threads |
number of threads. Default |
Value
cdcov.test
returns a list with class "htest" containing the following components:
statistic |
conditional distance covariance statistic. |
p.value |
the |
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. |
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
Examples
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)