bcov.test {Ball}  R Documentation 
Ball Covariance test of independence. Ball covariance are generic dependence measures in Banach spaces.
bcov.test(x, ...) ## Default S3 method: bcov.test( x, y = NULL, num.permutations = 99, method = c("permutation", "limit"), distance = FALSE, weight = FALSE, seed = 1, num.threads = 0, ... ) ## S3 method for class 'formula' bcov.test(formula, data, subset, na.action, ...)
x 
a numeric vector, matrix, data.frame, or a list containing at least two numeric vectors, matrices, or data.frames. 
... 
further arguments to be passed to or from methods. 
y 
a numeric vector, matrix, or data.frame. 
num.permutations 
the number of permutation replications. When 
method 
if 
distance 
if 
weight 
a logical or character string used to choose the weight form of Ball Covariance statistic..
If input is a character string, it must be one of 
seed 
the random seed. Default 
num.threads 
number of threads. If 
formula 
a formula of the form 
data 
an optional matrix or data frame (or similar: see 
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 
bcov.test
is nonparametric tests of independence in Banach spaces.
It can detect the dependence between two random objects (variables) and
the mutual dependence among at least three random objects (variables).
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
, this list
must contain at least
two numeric vectors, matrices, or data.frames, and each element of this list
must with the same sample size. Moreover, data pass to x
or y
must not contain missing or infinite values.
If distance = TRUE
, x
is considered as a distance matrix or a list containing distance matrices,
and y
is considered as a distance matrix; otherwise, these arguments are treated as data.
bcov.test
utilizes the Ball Covariance statistics (see bcov
) to measure dependence and
derives a pvalue via replicating the random permutation num.permutations
times.
See Pan et al 2018 for theoretical properties of the test, including statistical consistency.
If num.permutations > 0
, bcov.test
returns a htest
class object containing the following components:

Ball Covariance statistic. 

the pvalue for the test. 

permutation replications of the test statistic. 

sample size. 

a 

a character string describing the alternative hypothesis. 

a character string indicating what type of test was performed. 

description of data. 
If num.permutations = 0
, bcov.test
returns a statistic value.
Actually, bcov.test
simultaneously computing Ball Covariance statistics with
"constant"
, "probability"
, and "chisquare"
weights.
Users can get other Ball Covariance statistics with different weight and their corresponding pvalues
in the complete.info
element of output. We give a quick example below to illustrate.
Wenliang Pan, Xueqin Wang, Heping Zhang, Hongtu Zhu, Jin Zhu
Wenliang Pan, Xueqin Wang, Heping Zhang, Hongtu Zhu & Jin Zhu (2019) Ball Covariance: A Generic Measure of Dependence in Banach Space, Journal of the American Statistical Association, DOI: 10.1080/01621459.2018.1543600
Jin Zhu, Wenliang Pan, Wei Zheng, and Xueqin Wang (2021). Ball: An R Package for Detecting Distribution Difference and Association in Metric Spaces, Journal of Statistical Software, Vol.97(6), doi: 10.18637/jss.v097.i06.
set.seed(1) ################# Quick Start ################# noise < runif(50, min = 0.3, max = 0.3) x < runif(50, 0, 4*pi) y < cos(x) + noise # plot(x, y) res < bcov.test(x, y) res ## get all Ball Covariance statistics: res[["complete.info"]][["statistic"]] ## get all test result: res[["complete.info"]][["p.value"]] ################# Quick Start ################# x < matrix(runif(50 * 2, pi, pi), nrow = 50, ncol = 2) noise < runif(50, min = 0.1, max = 0.1) y < sin(x[,1] + x[,2]) + noise bcov.test(x = x, y = y, weight = "prob") ################# Ball Covariance Test for NonHilbert 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 = "prob") ################# Mutual Independence Test ################# x < rnorm(50) y < (x > 0) * x + rnorm(50) z < (x <= 0) * x + rnorm(50) data_list < list(x, y, z) bcov.test(data_list) data_list < lapply(data_list, function(x) { as.matrix(dist(x)) }) bcov.test(data_list, distance = TRUE) bcov.test(data_list, distance = FALSE, weight = "chi") ################# Mutual Independence Test for Meteorology data ################# data("meteorology") bcov.test(meteorology) ################ Testing via approximate limit distribution ################# ## Not run: set.seed(1) n < 2000 x < rnorm(n) y < rnorm(n) bcov.test(x, y, method = "limit") bcov.test(x, y) ## End(Not run) ################ Formula interface ################ ## independence test: bcov.test(~ CONT + INTG, data = USJudgeRatings) ## independence test with chisquare weight: bcov.test(~ CONT + INTG, data = USJudgeRatings, weight = "chi") ## mutual independence test: bcov.test(~ CONT + INTG + DMNR, data = USJudgeRatings)