medil.independence_testing.xicorr

medil.independence_testing.xicorr(x: numpy.typing.ArrayLike, y: numpy.typing.ArrayLike, ties: bool = True) XiCorrResult[source]

Compute the cross rank increment correlation coefficient xi [1].

Parameters:
  • x (array_like) – Arrays of rankings, of the same shape. If arrays are not 1-D, they will be flattened to 1-D.

  • y (array_like) – Arrays of rankings, of the same shape. If arrays are not 1-D, they will be flattened to 1-D.

  • ties (bool, optional) – If ties is True, the algorithm assumes that the data has ties and employs the more elaborated theory for calculating s.d. and P-value. Otherwise, it uses the simpler theory. There is no harm in putting ties = True even if there are no ties.

Returns:

  • correlation (float) – The tau statistic.

  • pvalue (float) – P-values computed by the asymptotic theory.

See also

spearmanr

Calculates a Spearman rank-order correlation coefficient.

Example:
>>> from xicorrelation import xicorr
>>> x = [1, 2, 3, 4, 5]
>>> y = [1, 4, 9, 16, 25]
>>> xi, pvalue = xicorr(x, y)
>>> print(xi, pvalue)

References

Examples

>>> from scipy import stats
>>> x1 = [12, 2, 1, 12, 2]
>>> x2 = [1, 4, 7, 1, 0]
>>> xi, p_value, _ = xicorr(x1, x2)
>>> tau
-0.47140452079103173
>>> p_value
0.2827454599327748