dcor.independence.distance_covariance_test

distance_covariance_test(x, y, *, num_resamples=0, exponent=1, random_state=None, n_jobs=1)[source]

Test of distance covariance independence.

Compute the test of independence based on the distance covariance, for two random vectors.

The test is a permutation test where the null hypothesis is that the two random vectors are independent.

Parameters
  • x (T) – First random vector. The columns correspond with the individual random variables while the rows are individual instances of the random vector.

  • y (T) – Second random vector. The columns correspond with the individual random variables while the rows are individual instances of the random vector.

  • exponent (float) – Exponent of the Euclidean distance, in the range \((0, 2)\). Equivalently, it is twice the Hurst parameter of fractional Brownian motion.

  • num_resamples (int) – Number of permutations resamples to take in the permutation test.

  • random_state (Optional[Union[RandomState, Generator, int]]) – Random state to generate the permutations.

  • n_jobs (int) – Number of jobs executed in parallel by Joblib.

Returns

Results of the hypothesis test.

Return type

HypothesisTest[T]

See also

distance_covariance

Examples

>>> import numpy as np
>>> import dcor
>>> a = np.array([[1, 2, 3, 4],
...               [5, 6, 7, 8],
...               [9, 10, 11, 12],
...               [13, 14, 15, 16]])
>>> b = np.array([[1, 0, 0, 1],
...               [0, 1, 1, 1],
...               [1, 1, 1, 1],
...               [1, 1, 0, 1]])
>>> dcor.independence.distance_covariance_test(a, a)
HypothesisTest(pvalue=1.0, statistic=208.0)
>>> dcor.independence.distance_covariance_test(a, b)
...                                      
HypothesisTest(pvalue=1.0, statistic=11.75323056...)
>>> dcor.independence.distance_covariance_test(b, b)
HypothesisTest(pvalue=1.0, statistic=1.3604610...)
>>> dcor.independence.distance_covariance_test(a, b,
... num_resamples=5, random_state=0)
HypothesisTest(pvalue=0.5, statistic=11.7532305...)
>>> dcor.independence.distance_covariance_test(a, b,
... num_resamples=5, random_state=13)
HypothesisTest(pvalue=0.3333333..., statistic=11.7532305...)
>>> dcor.independence.distance_covariance_test(a, a,
... num_resamples=7, random_state=0)
HypothesisTest(pvalue=0.125, statistic=208.0)