Learn R Programming

Ball (version 1.3.7)

bcov.test: Ball Covariance Test

Description

Ball covariance test of multivariate independence. Ball covariance are generic multivariate measures of dependence in Banach space.

Usage

bcov.test(x, ...)

# S3 method for default bcov.test(x, y = NULL, num.permutations = 99, distance = FALSE, weight = FALSE, seed = 4, num.threads = 1, ...)

# S3 method for formula bcov.test(formula, data, subset, na.action, ...)

Arguments

x

a numeric vector, matirx, data.frame or dist object or list containing numeric vector, matrix, data.frame, or dist object.

...

further arguments to be passed to or from methods.

y

a numeric vector, matirx, data.frame or dist object.

num.permutations

the number of permutation replications, when num.permutations equals to 0, the function returns the sample version of ball divergence. Default: num.permutations = 99

distance

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

weight

a logical or character value used to choose the form of weight. If weight = FALSE, the ball covariance / correlation with constant weight is used. Alternatively, weight = TRUE and weight = "prob" indicates the probability weight is chosen while setting weight = "chisq" means select the Chi-square weight. Note that this arguments actually only influences the printed result in R console and is only available for the bcov.test function at present. Default: weight = FALSE

seed

the random seed.

num.threads

Number of threads. Default num.threads = 1.

formula

a formula of the form ~ u + v, where each of u and v are numeric variables giving the data values for one sample. The samples must be of the same length.

data

an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).

subset

an optional vector specifying a subset of observations to be used.

na.action

a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").

Value

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

statistic

ball covariance or ball correlation statistic.

p.value

the p-value for the test.

replicates

permutation replications of the test statistic.

size

sample size.

complete.info

a list containing multiple statistics value and their corresponding $p$ value.

alternative

a character string describing the alternative hypothesis.

method

a character string indicating what type of test was performed.

data.name

description of data.

Details

bcov.test are non-parametric tests of multivariate independence in Banach space. The test decision is obtained via permutation, with num.permutations replicates.

If two samples are pass to arguments x and y, the sample sizes (i.e. number of rows or length of the vector) of the two variables must agree. If a list object is passed to x, each element must with same sample sizes. Moreover, data pass to x or y must not contain missing or infinite values. If we set distance = TRUE, arguments x, y can be a dist object or a symmetric numeric matrix recording distance between samples; otherwise, these arguments are treated as data.

The bcov.test statistic is bcov or bcor which are dependence measure in Banach space. The bcor test statistic is based on the normalized coefficient of ball covariance. (See the manual page for bcov or bcor.)

For the general problem of testing independence when the distributions of \(X\) and \(Y\) are unknown, the test based on bcov can be implemented as a permutation test. See (Jin et al 2018) for theoretical properties of the test, including statistical consistency.

References

Jin, Zhu, Wenliang Pan, Wei Zheng, and Xueqin Wang (2018). Ball: An R package for detecting distribution difference and association in metric spaces. arXiv preprint arXiv:1811.03750. URL http://arxiv.org/abs/1811.03750.

See Also

bcov, bcor

Examples

Run this code
# NOT RUN {
set.seed(1)

################# Quick Start #################
error <- runif(50, min = -0.3, max = 0.3)
x <- runif(50, 0, 4*pi)
y <- cos(x) + error
# plot(x, y)
bcov.test(x, y)

################# Quick Start #################
x <- matrix(runif(50 * 2, -pi, pi), nrow = 50, ncol = 2)
error <- runif(50, min = -0.3, max = 0.3)
y <- (sin((x[,1])^2 + x[,2])) + error
bcov.test(x = x, y = y)

################# Ball Covariance Test for Non-Hilbert Data #################
# load data:
data("ArcticLake")
# Distance matrix between y:
Dy <- nhdist(ArcticLake[["x"]], method = "compositional")
# Distance matrix between x:
Dx <- dist(ArcticLake[["depth"]])
# hypothesis test with BCov:
bcov.test(x = Dx, y = Dy, distance = TRUE)

################  Weighted Ball Covariance Test  #################
data("ArcticLake")
Dy <- nhdist(ArcticLake[["x"]], method = "compositional")
Dx <- dist(ArcticLake[["depth"]])
# hypothesis test with weighted BCov:
bcov.test(x = Dx, y = Dy, distance = TRUE, weight = TRUE)

################# Mutual Independence Test #################
x <- rnorm(30)
y <- (x > 0) * x + rnorm(30)
z <- (x <= 0) * x + rnorm(30)
data_list <- list(x, y, z)
bcov.test(data_list)

################# Mutual Independence Test for Meteorology data #################
data("meteorology")
bcov.test(meteorology)

################  Formula interface  ################
## independence test:
bcov.test(~ CONT + INTG, data = USJudgeRatings)
## mutual independence test:
bcov.test(~ CONT + INTG + DMNR, data = USJudgeRatings)
# }

Run the code above in your browser using DataLab