| Type: | Package |
| Title: | Non-Parametric Tests of Independence Between Random Vectors |
| Version: | 0.7 |
| Date: | 2026-07-06 |
| Maintainer: | Pierre Lafaye De Micheaux <lafaye@unsw.edu.au> |
| Description: | Non-parametric tests of independence (mutual or serial) between some quantitative random vectors, as described in Bilodeau M. and Lafaye de Micheaux P. (2009) <doi:10.1016/j.jspi.2008.11.006>, in Beran R., Bilodeau M. and Lafaye de Micheaux P. (2007) <doi:10.1016/j.jmva.2007.01.009> and in Fan Y., Lafaye de Micheaux P., Penev S. and Salopek D. (2017) <doi:10.1016/j.jmva.2016.09.014>. |
| License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
| Depends: | R (≥ 2.6.0), xtable, CompQuadForm, MASS, Runuran, parallel |
| Packaged: | 2026-07-06 06:53:01 UTC; lafaye |
| Copyright: | For LAPACK/BLAS routines in src (Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., Courant Institute, Argonne National Lab, and Rice University). |
| NeedsCompilation: | yes |
| Author: | Pierre Lafaye De Micheaux
|
| Repository: | CRAN |
| Date/Publication: | 2026-07-14 16:40:18 UTC |
Tests for mutual or serial independence between categorical variables
Description
The tests are constructed from the Möbius transformation applied to the probability cells in a multi-way contingency table. The Pearson chi-squared test of mutual independence is partitioned into A-dependence statistics over all subsets A of variables. The goal of the partition is to identify subsets of dependent variables when the mutual independence hypothesis is rejected by the Pearson chi-squared test. The methodology can be directly adapted to test for serial independence of d successive observations of a stationary categorical time series.
For categorical time series, especially those of a nominal (non ordinal) nature, the user should be aware that tests of serial independence obtained by methods suited to quantitative sequences by quantification of the labels are not invariant to permutation of the labels contrary to the test described here.
Usage
A.dep.tests(Xmat, choice = 1, d = 0, m = d, freqname = "", type = "text")
Arguments
Xmat |
Table, matrix or data-frame of the contingency table data,
if |
choice |
Integer. 1 for mutual independence, 2 for serial independence. |
d |
Integer. Used only if |
m |
Integer. Maximum cardinality of subsets |
freqname |
Character. Used only if |
type |
"text" or "html" |
Value
Returns an object of class A.dep.tests, inheriting from list,
with a print method. The object contains the following components:
TA |
|
fA |
degrees of freedom of the |
pvalA |
|
X |
summary of the results. |
X2 |
test statistic for mutual independence obtained by the
sum of the |
Y2 |
test statistic for serial independence obtained by the
sum of the |
f |
number of degrees of freedom associated with the test
statistic |
pval |
the |
Author(s)
Bilodeau M., Lafaye de Micheaux P.
References
Bilodeau M., Lafaye de Micheaux P. (2009). A-dependence statistics for mutual and serial independence of categorical variables, Journal of Statistical Planning and Inference, 139, 2407-2419.
Agresti A. (2002). Categorical data analysis, Wiley, p. 322
Whisenant E.C., Rasheed B.K.A., Ostrer H., Bhatnagar Y.M. (1991). Evolution and sequence analysis of a human Y-chromosomal DNA fragment, J. Mol. Evol., 33, 133-141.
Examples
# Test of mutual independence between 3 independent Bernoulli variables.
n <- 100
data <- data.frame(X1 = rbinom(n, 1, 0.3), X2 = rbinom(n, 1, 0.3) , X3 =
rbinom(n, 1, 0.3))
X <- table(data)
A.dep.tests(X)
# Test of mutual independence between 4 variables which are
# 2-independent and 3-independent, but are 4-dependent.
n <- 100
W <- sample(x = 1:8, size = n, TRUE)
X1 <- W %in% c(1, 2, 3, 5)
X2 <- W %in% c(1, 2, 4, 6)
X3 <- W %in% c(1, 3, 4, 7)
X4 <- W %in% c(2, 3, 4, 8)
data <- data.frame(X1, X2, X3, X4)
X <- table(data)
A.dep.tests(X)
# Test of serial independence of a nucleotide sequence of length
# 4156 described in Whisenant et al. (1991).
data(dna)
x2 <- dna[1]
for (i in 2:length(dna)) x2 <- paste(x2, dna[i], sep = "")
x <- unlist(strsplit(x2, ""))
x[x == "a" | x == "g"] <- "r"
x[x == "c" | x== "t"] <- "y"
out <- A.dep.tests(x, choice = 2, d = 1501, m = 2)$TA[[1]]
plot(100:1500, out[100:1500], xlab = "lag j", ylab = "T(1,j+1)", pch = 19)
abline(h = qchisq(.995, df = 1))
# Analysis of a contingency table in Agresti (2002) p. 322
data(highschool)
A.dep.tests(highschool, freqname = "count")
Nonparametric tests of independence between random vectors
Description
This function can be used for the following two problems: 1) testing mutual independence between some numerical random vectors, and 2) testing for serial independence of a multivariate stationary quantitative time series. The proposed test does not assume continuous marginals. It is valid for any probability distribution. It is also invariant with respect to the affine general linear group of transformations on the vectors. This test is based on a characterization of mutual independence defined from probabilities of half-spaces in a combinatorial formula of Möbius. As such, it is a natural generalization of tests of independence between univariate random variables using the empirical distribution function. Without the assumption that each vector is one-dimensional with a continuous cumulative distribution function, any test of independence can not be distribution free. The critical values of the proposed test are thus computed with the bootstrap which was shown to be consistent in this context.
Usage
dependogram(X, vecd.or.p, N = 10, B = 2000, alpha = 0.05, display =
TRUE, graphics = TRUE, nbclus = 1)
Arguments
X |
Data.frame or matrix with observations corresponding to rows and variables to columns. |
vecd.or.p |
For the mutual independence problem 1), a vector giving the sizes of each subvector. For the serial independence problem 2), an integer indicating the number of consecutive observations. |
N |
Integer. Number of points of the discretization to obtain directions on the sphere in order to evaluate the value of the test statistic. |
B |
Integer. Number of bootstrap samples. Note that |
alpha |
Double. Global significance level of the test. |
display |
Logical. TRUE to display values of the |
graphics |
Logical. TRUE to plot the dependogram. |
nbclus |
Integer. Number of nodes in the cluster. Used only for parallel computations. |
Value
A list with the following components:
In the mutual independence case:
norm.RnA |
Supremum norm (Kolmogorov). Test statistic is
|
Rn |
Maximum value of |
rA |
Critical value of the bootstrap distribution of the test
statistic |
r |
Critical value of the bootstrap distribution of the test
statistic |
RnAsstar |
Matrix of size |
In the serial case:
norm.SnA |
Supremum norm (Kolmogorov). Test statistic is
|
Sn |
Maximum value of |
sA |
Critical value of the bootstrap distribution of the test
statistic |
s |
Critical value of the bootstrap distribution of the test
statistic |
SnAsstar |
Matrix of size |
Author(s)
Bilodeau M., Lafaye de Micheaux P.
References
Beran R., Bilodeau M., Lafaye de Micheaux P. (2007). Nonparametric tests of independence between random vectors, Journal of Multivariate Analysis, 98, 1805-1824.
Examples
# NOTE: In real applications, B should be set to at least 1000.
# Example 4.1: Test of mutual independence between four discrete Poisson
# variables. The pair (X1,X2) is independent of the pair (X3,X4), with
# each pair having a correlation of 3/4.
# NOTE: with B=1000, this one took 65s with nbclus=1 and 15s with nbclus=7 on my computer.
n <- 100
W1 <- rpois(n, 1)
W3 <- rpois(n, 1)
W4 <- rpois(n, 1)
W6 <- rpois(n, 1)
W2 <- rpois(n, 3)
W5 <- rpois(n, 3)
X1 <- W1 + W2
X2 <- W2 + W3
X3 <- W4 + W5
X4 <- W5 + W6
X <- cbind(X1, X2, X3, X4)
dependogram(X, vecd.or.p = c(1, 1, 1, 1), N = 10, B = 20, alpha = 0.05,
display = TRUE, graphics = TRUE)
# Example 4.2: Test of mutual independence between three bivariate
# vectors. The block-diagonal structure of the covariance matrix is
# such that only the second and third subvectors are dependent.
# NOTE: with B=2000, this one took 3.8h with nbclus=1 on my computer.
n <- 50
mu <- rep(0,6)
Psi <- matrix(c(1, 0, 0, 0, 0, 0,
0, 1, 0, 0, 0, 0,
0, 0, 1, 0,.4,.5,
0, 0, 0, 1,.1,.2,
0, 0,.4,.1, 1, 0,
0, 0,.5,.2, 0, 1), nrow = 6, byrow = TRUE)
X <- mvrnorm(n, mu, Psi)
dependogram(X, vecd.or.p = c(2, 2, 2), N = 10, B = 20, alpha = 0.05,
display = TRUE, graphics = TRUE)
# Example 4.3: Test of mutual independence between 4 dependent binary
# variables which are 2-independent (pairwise) and also 3-independent
# (any 3 of the 4 variables are mutually independent).
n <- 100
W <- sample(x = 1:8, size = n, TRUE)
X1 <- W %in% c(1, 2, 3, 5)
X2 <- W %in% c(1, 2, 4, 6)
X3 <- W %in% c(1, 3, 4, 7)
X4 <- W %in% c(2, 3, 4, 8)
X <- cbind(X1, X2, X3, X4)
dependogram(X, vecd.or.p = c(1, 1, 1, 1), N = 10, B = 20, alpha = 0.05,
display = TRUE, graphics = TRUE)
# Example 4.4: Test of serial independence of binary sequences of zeros
# and ones. The sequence W is an i.i.d. sequence. The sequence Y is
# dependent at lag 3.
n <- 100 ; lag <- 3
W <- rbinom(n, 1, 0.8)
Y <- W[1:(n - lag)] * W[(1 + lag):n]
dependogram(W, vecd.or.p = 4, N = 10, B = 20, alpha = 0.05, display =
TRUE, graphics = TRUE)
dependogram(Y, vecd.or.p = 4, N = 10, B = 20, alpha = 0.05, display =
TRUE, graphics = TRUE)
# Example 4.5: Test of serial independence of sequences of directional
# data on the 2-dimensional sphere. The sequence W is an
# i.i.d. sequence. The sequence Y is dependent at lag 1.
# NOTE: with B=2000, this one took 7.9h with nbclus=1 on my computer.
n <- 75 ; lag <- 1
U <- matrix(rnorm(2 * n), nrow = n, ncol = 2)
W <- U[1:(n - lag),] + sqrt(2) * U[(1 + lag):n,]
Y <- W / apply(W, MARGIN = 1, FUN = function(x) {sqrt(x[1] ^ 2 + x[2] ^ 2)})
dependogram(Y, vecd.or.p = 3, N = 10, B = 20, alpha = 0.05, display =
TRUE, graphics = TRUE)
# This one always gives the same value of the test statistic:
x <- rnorm(100)
dependogram(X = cbind(x, x), vecd.or.p = c(1, 1), N = 2, B = 2, alpha =
0.05, display = FALSE, graphics = FALSE, nbclus = 1)$Rn
# This is correct because this is equivalent to computing:
I <- 1:100
n <- 100
sqrt(n) * max(I/n - I ^ 2 / n ^ 2)
dna sequence
Description
This data from Whisenant et al. (1991) is a nucleotides sequence of 4156 base pairs (bp). The categorical variable represents the nucleotide which is either one of the two purines (r), adenine (a) or guanine (g), or one of the two pyrimidines (y), cytosine (c) or thymine (t).
Usage
data(dna)
Format
A character vector of length 70 representing 70 consecutive segments of a dna strand of length 4156.
References
Whisenant E.C., Rasheed B.K.A., Ostrer H., Bhatnagar Y.M. (1991). Evolution and sequence analysis of a human Y-chromosomal DNA fragment, J. Mol. Evol., 33, 133-141.
Examples
data(dna)
x2 <- dna[1]
for (i in 2:length(dna)) x2 <- paste(x2, dna[i], sep = "")
x <- unlist(strsplit(x2, ""))
Highschool data on alcohol, cigarette and marijuana use for highschool seniors
Description
Data from a 1992 survey by the Wright State University School of Medecine and the United Health Services in Dayton, Ohio. The survey asked 2276 students in their final year of highschool in a nonurban area near Dayton, Ohio, whether they had ever used alcohol, cigarettes, or marijuana.
Usage
data(highschool)
Format
A data frame of 8 observations on the variables:
- alcohol
a factor vector with components "yes" or "no".
- cigarette
a factor vector with components "yes" or "no".
- marijuana
a factor vector with components "yes" or "no".
- count
a numeric vector of frequencies.
References
Agresti A. (2002). Categorical data analysis, Wiley, p. 322.
Examples
data(highschool)
Computation of the multidimensional distance covariance statistic for mutual independence using characteristic functions.
Description
Computation of the multidimensional distance covariance statistic for mutual independence using
characteristic functions. Compute the eigenvalues associated with the empirical covariance of the
limiting Gaussian procces. Compute the p-value associated with the test statistic, using the Imhof procedure.
Usage
mdcov(X, vecd, a = 1, weight.choice = 1, N = 200, cubature = FALSE, K =
100, epsrel = 10 ^ -6, norming = TRUE, thresh.eigen = 10 ^ -8, estim.a =
FALSE, Cpp = TRUE, pval.comp = TRUE)
Arguments
X |
Data.frame or matrix with observations corresponding to rows and variables to columns. |
vecd |
a vector giving the sizes of each subvector. |
a |
parameter for the weight function. |
weight.choice |
Integer value in 1, 2, 3, 4, 5 corresponding to the choice in our paper. |
N |
Number of Monte-Carlo samples. |
cubature |
Logical. If |
K |
Number of eigenvalues to compute. |
epsrel |
relative accuracy requested for the Imhof procedure. |
norming |
Logical. Should we normalize the test statistic with |
thresh.eigen |
We will not compute eigenvalues (involved in the limiting distribution) below that threshold. |
estim.a |
Logical. Should we automatically estimate the value of |
Cpp |
Logical. If |
pval.comp |
Logical. If |
Value
A list with the following components:
mdcov |
the value of the statistic |
Hn |
the denominator of |
pvalue |
the |
lambdas |
the vector of eigenvalues computed (they have not been divided by their sum) |
Author(s)
Lafaye de Micheaux P.
References
Fan Y., Lafaye de Micheaux P., Penev S. and Salopek D. (2017). Multivariate nonparametric test of independence, Journal of Multivariate Analysis, 153, 189-210.
Examples
a <- 1
# 4.1 Dependence among four discrete variables
set.seed(1)
n <- 100
w1 <- rpois(n, 1)
w3 <- rpois(n, 1)
w4 <- rpois(n, 1)
w6 <- rpois(n, 1)
w2 <- rpois(n, 3)
w5 <- rpois(n, 3)
x1 <- w1 + w2
x2 <- w2 + w3
x3 <- w4 + w5
x4 <- w5 + w6
X <- cbind(x1, x2, x3, x4)
mdcov(X, vecd = c(2, 2), a, weight.choice = 1, N = 100, cubature = TRUE)
mdcov(X, vecd = c(1, 1, 1, 1), a, weight.choice = 1, N = 100, cubature = TRUE)
X <- cbind(x1, x2)
mdcov(X, vecd = c(1, 1), a, weight.choice = 1, N = 100, cubature = TRUE)
X <- cbind(x3, x4)
mdcov(X, vecd = c(1, 1), a, weight.choice = 1, N = 100, cubature = TRUE)
# 4.2 Dependence between three bivariate vectors
set.seed(2)
n <- 200
Sigma <- matrix(c(
1 , 0 , 0 , 0 , 0 , 0 ,
0 , 1 , 0 , 0 , 0 , 0 ,
0 , 0 , 1 , 0 , .4 , .5 ,
0 , 0 , 0 , 1 , .1 , .2 ,
0 , 0 , .4 , .1 , 1 , 0 ,
0 , 0 , .5 , .2 , 0 , 1 ) ,
nrow = 6 , ncol = 6)
W <- mvrnorm(n = n, mu = rep(0,6), Sigma = Sigma, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)
mdcov(W, vecd = c(2, 2, 2), a, weight.choice = 1, N = 100, cubature = TRUE, epsrel = 10 ^ -7)
# X^{(1)} with X^{(2)}^2
mdcov(W[,1:4], vecd = c(2, 2), a, weight.choice = 1, N = 100, cubature = TRUE)
# X^{(2)} with X^{(3)}^2
mdcov(W[,2:6], vecd = c(2, 2), a, weight.choice = 1, N = 100, cubature = TRUE)
# X^{(1)} with X^{(3)}^2
mdcov(W[,c(1:2, 4:6)], vecd = c(2, 2), a, weight.choice = 1, N = 100, cubature = TRUE)
# 4.3 Four-dependent variables which are 2-independent and 3-independent
set.seed(3)
n <- 300
W <- sample(1:8, n, replace = TRUE)
X1 <- W %in% c(1, 2, 3, 5)
X2 <- W %in% c(1, 2, 4, 6)
X3 <- W %in% c(1, 3, 4, 7)
X4 <- W %in% c(2, 3, 4, 8)
X <- cbind(X1, X2, X3, X4)
# pairwise independence
mdcov(X[,c(1, 2)], vecd = c(1, 1), a, weight.choice = 1, cubature = TRUE)
mdcov(X[,c(1, 3)], vecd = c(1, 1), a, weight.choice = 1, N = 100, cubature = TRUE)
mdcov(X[,c(1, 4)], vecd = c(1, 1), a, weight.choice = 1, cubature = TRUE)
mdcov(X[,c(2, 3)], vecd = c(1, 1), a, weight.choice = 1, cubature = TRUE)
mdcov(X[,c(2, 4)], vecd = c(1, 1), a, weight.choice = 1, cubature = TRUE)
mdcov(X[,c(3, 4)], vecd = c(1, 1), a, weight.choice = 1, cubature = TRUE)
# 3-independence
mdcov(X[,c(1, 2, 3)], vecd = c(1, 1, 1), a, weight.choice =
1, cubature = TRUE)
mdcov(X[,c(1, 2, 4)], vecd = c(1, 1, 1), a, weight.choice =
1, cubature = TRUE)
mdcov(X[,c(1, 3, 4)], vecd = c(1, 1, 1), a, weight.choice =
1, cubature = TRUE)
mdcov(X[,c(2, 3, 4)], vecd = c(1, 1, 1), a, weight.choice =
1, cubature = TRUE)
# 4-dependence
mdcov(X, vecd = c(1, 1, 1, 1), a, weight.choice = 1, cubature = TRUE)